Replace use of attr with prop for booleans

Recommened way of setting boolean HTML attributes is by $.prop(boolean) method not $.attr(boolean) because it sets DOM object property not an attribute. Latter works because of jquery's backward compatibility. This patch makes things clearer.

Some info about prop and attr: http://stackoverflow.com/a/5876747

https://fedorahosted.org/freeipa/ticket/2817
This commit is contained in:
Petr Vobornik 2012-07-26 11:17:28 +02:00
parent 1a94109f4a
commit c2783b9b54
5 changed files with 33 additions and 41 deletions

View File

@ -492,7 +492,7 @@ IPA.attributes_widget = function(spec) {
type: "checkbox", type: "checkbox",
click: function() { click: function() {
$('.aci-attribute', that.table). $('.aci-attribute', that.table).
attr('checked', $(this).attr('checked')); prop('checked', $(this).prop('checked'));
that.value_changed.notify([], that); that.value_changed.notify([], that);
} }
}) })

View File

@ -1038,9 +1038,9 @@ IPA.association_facet = function (spec, no_init) {
that.refresh = function() { that.refresh = function() {
if (that.association_type == 'direct') { if (that.association_type == 'direct') {
if (that.direct_radio) that.direct_radio.attr('checked', true); if (that.direct_radio) that.direct_radio.prop('checked', true);
} else { } else {
if (that.indirect_radio) that.indirect_radio.attr('checked', true); if (that.indirect_radio) that.indirect_radio.prop('checked', true);
} }
var pkey = that.entity.get_primary_key(); var pkey = that.entity.get_primary_key();

View File

@ -512,8 +512,8 @@ IPA.add_dns_zone_name_policy = function() {
var name_from_ip_f = this.container.fields.get_field('name_from_ip'); var name_from_ip_f = this.container.fields.get_field('name_from_ip');
idnsname_w.radio_clicked.attach(function() { idnsname_w.radio_clicked.attach(function() {
idnsname_w.input.attr('disabled', false); idnsname_w.input.prop('disabled', false);
name_from_ip_w.input.attr('disabled', true); name_from_ip_w.input.prop('disabled', true);
idnsname_f.set_required(true); idnsname_f.set_required(true);
name_from_ip_f.set_required(false); name_from_ip_f.set_required(false);
@ -522,8 +522,8 @@ IPA.add_dns_zone_name_policy = function() {
}); });
name_from_ip_w.radio_clicked.attach(function() { name_from_ip_w.radio_clicked.attach(function() {
idnsname_w.input.attr('disabled', true); idnsname_w.input.prop('disabled', true);
name_from_ip_w.input.attr('disabled', false); name_from_ip_w.input.prop('disabled', false);
idnsname_f.set_required(false); idnsname_f.set_required(false);
name_from_ip_f.set_required(true); name_from_ip_f.set_required(true);

View File

@ -279,7 +279,7 @@ IPA.hbac.test_select_facet = function(spec) {
that.table.set_values = function(values) { that.table.set_values = function(values) {
if (values && values.length && values[0] === '__external__') { if (values && values.length && values[0] === '__external__') {
if (that.external_radio) that.external_radio.attr('checked', true); if (that.external_radio) that.external_radio.prop('checked', true);
} else { } else {
that.table.table_set_values(values); that.table.table_set_values(values);
} }
@ -393,7 +393,7 @@ IPA.hbac.test_select_facet = function(spec) {
that.reset = function() { that.reset = function() {
delete that.selected_values; delete that.selected_values;
if (that.external_radio) that.external_radio.attr('checked', false); if (that.external_radio) that.external_radio.prop('checked', false);
if (that.external_text) that.external_text.val(''); if (that.external_text) that.external_text.val('');
}; };
@ -482,8 +482,8 @@ IPA.hbac.test_rules_facet = function(spec) {
that.reset = function() { that.reset = function() {
delete that.selected_values; delete that.selected_values;
if (that.enabled) that.enabled.attr('checked', false); if (that.enabled) that.enabled.prop('checked', false);
if (that.disabled) that.disabled.attr('checked', false); if (that.disabled) that.disabled.prop('checked', false);
}; };
that.save = function(record) { that.save = function(record) {
@ -655,8 +655,8 @@ IPA.hbac.test_run_facet = function(spec) {
delete that.data; delete that.data;
that.show_matched = true; that.show_matched = true;
that.show_unmatched = true; that.show_unmatched = true;
if (that.matched_checkbox) that.matched_checkbox.attr('checked', true); if (that.matched_checkbox) that.matched_checkbox.prop('checked', true);
if (that.unmatched_checkbox) that.unmatched_checkbox.attr('checked', true); if (that.unmatched_checkbox) that.unmatched_checkbox.prop('checked', true);
that.refresh(); that.refresh();
}; };

View File

@ -297,11 +297,7 @@ IPA.text_widget = function(spec) {
that.set_enabled = function(value) { that.set_enabled = function(value) {
if(value) { that.input.prop('disabled', !value);
that.input.removeAttr('disabled');
} else {
that.input.attr('disabled', 'disabled');
}
}; };
that.clear = function() { that.clear = function() {
@ -669,11 +665,11 @@ IPA.checkbox_widget = function (spec) {
value = that.checked; value = that.checked;
} }
that.input.attr('checked', value); that.input.prop('checked', value);
}; };
that.clear = function() { that.clear = function() {
that.input.attr('checked', false); that.input.prop('checked', false);
}; };
that.checkbox_save = that.save; that.checkbox_save = that.save;
@ -741,18 +737,18 @@ IPA.checkboxes_widget = function (spec) {
that.update = function(values) { that.update = function(values) {
var inputs = $('input[name="'+that.name+'"]', that.container); var inputs = $('input[name="'+that.name+'"]', that.container);
inputs.attr('checked', false); inputs.prop('checked', false);
for (var j=0; values && j<values.length; j++) { for (var j=0; values && j<values.length; j++) {
var value = values[j]; var value = values[j];
var input = $('input[name="'+that.name+'"][value="'+value+'"]', that.container); var input = $('input[name="'+that.name+'"][value="'+value+'"]', that.container);
if (!input.length) continue; if (!input.length) continue;
input.attr('checked', true); input.prop('checked', true);
} }
}; };
that.clear = function() { that.clear = function() {
$('input[name="'+that.name+'"]').attr('checked', false); $('input[name="'+that.name+'"]').prop('checked', false);
}; };
that.add_option = function(option) { that.add_option = function(option) {
@ -829,21 +825,21 @@ IPA.radio_widget = function(spec) {
var value = values && values.length ? values[0] : ''; var value = values && values.length ? values[0] : '';
var input = $(that.selector+'[value="'+value+'"]', that.container); var input = $(that.selector+'[value="'+value+'"]', that.container);
if (input.length) { if (input.length) {
input.attr('checked', true); input.prop('checked', true);
} else if (that.default_value) { } else if (that.default_value) {
input = $(that.selector+'[value="'+that.default_value+'"]', that.container); input = $(that.selector+'[value="'+that.default_value+'"]', that.container);
input.attr('checked', true); input.prop('checked', true);
} }
that.value_changed.notify([that.save()], that); that.value_changed.notify([that.save()], that);
}; };
that.clear = function() { that.clear = function() {
$(that.selector, that.container).attr('checked', false); $(that.selector, that.container).prop('checked', false);
if (that.default_value) { if (that.default_value) {
var input = $(that.selector+'[value="'+that.default_value+'"]', that.container); var input = $(that.selector+'[value="'+that.default_value+'"]', that.container);
input.attr('checked', true); input.prop('checked', true);
} }
}; };
@ -915,7 +911,7 @@ IPA.select_widget = function(spec) {
var value = values[0]; var value = values[0];
var option = $('option[value="'+value+'"]', that.select); var option = $('option[value="'+value+'"]', that.select);
if (!option.length) return; if (!option.length) return;
option.attr('selected', 'selected'); option.prop('selected', true);
}; };
that.empty = function() { that.empty = function() {
@ -923,7 +919,7 @@ IPA.select_widget = function(spec) {
}; };
that.clear = function() { that.clear = function() {
$('option', that.select).attr('selected', ''); $('option', that.select).prop('selected', false);
}; };
that.set_options_enabled = function(enabled, options) { that.set_options_enabled = function(enabled, options) {
@ -1521,24 +1517,24 @@ IPA.table_widget = function (spec) {
}; };
that.select_all = function() { that.select_all = function() {
$('input[name="'+that.name+'"]', that.thead).attr('checked', true). $('input[name="'+that.name+'"]', that.thead).prop('checked', true).
attr('title', IPA.messages.search.unselect_all); attr('title', IPA.messages.search.unselect_all);
$('input[name="'+that.name+'"]', that.tbody).attr('checked', true); $('input[name="'+that.name+'"]', that.tbody).prop('checked', true);
that.select_changed(); that.select_changed();
}; };
that.unselect_all = function() { that.unselect_all = function() {
$('input[name="'+that.name+'"]', that.thead).attr('checked', false). $('input[name="'+that.name+'"]', that.thead).prop('checked', false).
attr('title', IPA.messages.search.select_all); attr('title', IPA.messages.search.select_all);
$('input[name="'+that.name+'"]', that.tbody).attr('checked', false); $('input[name="'+that.name+'"]', that.tbody).prop('checked', false);
that.select_changed(); that.select_changed();
}; };
that.set_values = function(values) { that.set_values = function(values) {
$('input[name="'+that.name+'"]', that.tbody).attr('checked', false); $('input[name="'+that.name+'"]', that.tbody).prop('checked', false);
for (var i=0; values && i<values.length; i++) { for (var i=0; values && i<values.length; i++) {
var value = values[i]; var value = values[i];
$('input[name="'+that.name+'"][value="'+value+'"]', that.tbody).attr('checked', true); $('input[name="'+that.name+'"][value="'+value+'"]', that.tbody).prop('checked', true);
} }
that.select_changed(); that.select_changed();
}; };
@ -1697,11 +1693,7 @@ IPA.table_widget = function (spec) {
}; };
that.set_enabled = function(enabled) { that.set_enabled = function(enabled) {
if (enabled) { $('input[name="'+that.name+'"]', that.table).prop('disabled', !enabled);
$('input[name="'+that.name+'"]', that.table).attr('disabled', false);
} else {
$('input[name="'+that.name+'"]', that.table).attr('disabled', true);
}
}; };
that.clear = function() { that.clear = function() {
@ -2316,7 +2308,7 @@ IPA.combobox_widget = function(spec) {
// if no option found, skip // if no option found, skip
if (!option.length) return; if (!option.length) return;
option.attr('selected', 'selected'); option.prop('selected', true);
that.set_value(option.val()); that.set_value(option.val());
that.value_changed.notify([], that); that.value_changed.notify([], that);