Reputation: 1
I have added the java script in the xml file and added widget in the smtp_pass field.
<group string="Security and Authentication" colspan="4">
<field name="smtp_encryption" on_change="on_change_encryption(smtp_encryption)"/>
<script>
openerp.MODULE_NAME = function (instance) {
instance.MODULE_NAME.Password = instance.web.form.FieldChar.extend({
events: {
"click .password": "toggle_password",
},
initialize_content: function() {
this.setupFocus(this.$('input'));
this.$('input').parent().append('<i class="fa fa-fw fa-eye password" style="position: relative;margin-bottom: 0px;bottom: 20px;left: 90%;"/>');
},
toggle_password: function() {
var node = this.$('input');
if (node.attr('type') === 'password') {
node.prop('type', 'text');
$('i').toggleClass("fa-eye-slash");
} else {
node.prop('type', 'password');
$('i').removeClass('fa-eye-slash')
}
},
});
instance.web.form.widgets.add('password', 'instance.MODULE_NAME.Password');
};
</script>
<field name="smtp_user"/>
<field name="smtp_pass" password="True" widget='password'/>
And in python file i added the related field for smtp_pass
'smtp_pass': fields.char('Password',size=64, help="Optional password for SMTP authentication"),
'related_smtp_pass':fields.char(related='smtp_pass'),
Upvotes: 0
Views: 1536
Reputation: 26768
Using a field several times on the form view is not supported in Odoo 8.
You can add a related field to smtp_password
and use it to show the password.
related_smtp_password = fields.Char(related='smtp_password')
It is not possible to set the password attribute with conditions.
The char field is handled by the client widget, you can customize the behavior of the char field using the javascript.
You can extend the char widget and create a new one with an eye to the right corner to show or hide the password, you can try the following example:
openerp.MODULE_NAME = function (instance) {
instance.MODULE_NAME.Password = instance.web.form.FieldChar.extend({
events: {
"click .password": "toggle_password",
},
initialize_content: function() {
this.setupFocus(this.$('input'));
this.$('input').parent().append('<i class="fa fa-fw fa-eye password" style="position: relative;margin-bottom: 0px;bottom: 20px;left: 90%;"/>');
},
toggle_password: function() {
var node = this.$('input');
if (node.attr('type') === 'password') {
node.prop('type', 'text');
$('i').toggleClass("fa-eye-slash");
} else {
node.prop('type', 'password');
$('i').removeClass('fa-eye-slash')
}
},
});
instance.web.form.widgets.add('password', 'instance.MODULE_NAME.Password');
};
You have just to use the following declaratio in the form view:
<field name="smtp_password" password="True" widget='password'/>
Edit:
Create an XML file (templates.xml
) and add the following code:
<openerp>
<data>
<template id="assets_backend" name="Assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/MODULE_NAME/static/src/js/script.js"></script>
</xpath>
</template>
</data>
</openerp>
And add it to the data in the manifest file (__openerp__.py
):
'data': [
'templates.xml',
],
Then create the js file under /static/src/js/
and add the above javascript code.
Upvotes: 1