diff --git a/core/doctype/profile/profile.js b/core/doctype/profile/profile.js index e008621b42..d4d6eca93b 100644 --- a/core/doctype/profile/profile.js +++ b/core/doctype/profile/profile.js @@ -105,14 +105,15 @@ wn.RoleEditor = Class.extend({ var me = this; // uncheck all roles - $(this.wrapper).find('input[type="checkbox"]').removeAttr("checked"); + $(this.wrapper).find('input[type="checkbox"]') + .each(function(i, checkbox) { checkbox.checked = false; }); // set user roles as checked $.each(wn.model.get("UserRole", {parent: cur_frm.doc.name, parentfield: "user_roles"}), function(i, user_role) { - $(me.wrapper) - .find('[data-user-role="'+user_role.role - +'"] input[type="checkbox"]').attr('checked', 'checked'); + var checkbox = $(me.wrapper) + .find('[data-user-role="'+user_role.role+'"] input[type="checkbox"]').get(0); + if(checkbox) checkbox.checked = true; }); }, set_roles_in_table: function() { @@ -147,8 +148,7 @@ wn.RoleEditor = Class.extend({ var checked_roles = []; var unchecked_roles = []; $(this.wrapper).find('[data-user-role]').each(function() { - var $check = $(this).find('input[type="checkbox"]'); - if($check.attr('checked')) { + if($(this).find('input[type="checkbox"]:checked').length) { checked_roles.push($(this).attr('data-user-role')); } else { unchecked_roles.push($(this).attr('data-user-role')); diff --git a/public/js/wn/form/control.js b/public/js/wn/form/control.js index 8bc98a695b..d312f2d2dd 100644 --- a/public/js/wn/form/control.js +++ b/public/js/wn/form/control.js @@ -491,14 +491,13 @@ wn.ui.form.ControlSelect = wn.ui.form.ControlData.extend({ padding-left: 6px; padding-right: 6px; margin-left: 6px;'>\ ") .click(function() { - me.frm.attachments.new_attachment(); + me.frm.attachments.new_attachment(me.df.fieldname); }) .appendTo(this.input_area); $(document).on("upload_complete", function(event, filename, file_url) { if(cur_frm === me.frm) { me.set_options(); - me.set_input(filename ? ("files/" + filename) : file_url); } }) }, @@ -513,13 +512,18 @@ wn.ui.form.ControlSelect = wn.ui.form.ControlData.extend({ if(this.in_filter && options[0] != "") { options = add_lists([''], options); } - + + var selected = this.$input.find(":selected").val(); + this.$input.empty().add_options(options || []); + + if(selected) this.$input.val(selected); }, get_file_attachment_list: function() { if(!this.frm) return; var fl = wn.model.docinfo[this.frm.doctype][this.frm.docname]; - if(fl) { + if(fl && fl.attachments) { + fl = fl.attachments; this.set_description(""); var options = [""]; for(var fname in fl) {