Wednesday, January 14, 2015

In openERP, Get same value of one text field into another text field on change or on click of Checkbox


In openERP, Get same value of one text field into another text field on change or on click of Checkbox

This is the simple method used in openERP without writing the Javascript function.
Here I have taken example of Permanent Address will be same as Home Address if user checks the 'same as above' checkbox

Define your fields in .py file

_columns = {
'home_address': fields.text('Home Address'),
'permanent_address': fields.text('Permanent Address'),
'same_as_above':fields.boolean('Same As Above'),
}

Write the onchange function on checkbox in .py file

Note: for defining a checkbox in OpenERP the type of field will be a 'boolean'

def onchange_same_as_above(self,cr, uid, ids,same_as_above,home_address,context=None):
    value={}
    if same_as_above and home_address_new:
        if same_as_above == True:
            value = {'permanent_address':home_address}
    else:
        value = {'permanent_address':''}
    return {'value':value}

To display the above fields on the form write it in .xml file

<field name="home_address"/>
<field name="same_as_above" on_change="onchange_same_as_above(same_as_above, home_address)"/>
<field name="permanent_address" placeholder="Check Above Checkbox If Permanent Address is same as Home Address"/>















Below figure shows when user checks the 'Same As Above' checkbox 'Permanent Address' will be same as 'Home Address'

















Note: When user unchecks the checkbox 'Permanent Address' field will be blank.

Thanks,

Ujwala H. Pawade..



No comments:

Post a Comment