mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Fixed change tracking of checkboxes and radiobuttons in jquery.changetracker plugin
This commit is contained in:
parent
ddad7fb110
commit
64f6b460e9
@ -54,19 +54,24 @@
|
||||
this.initialize = function() {
|
||||
// optional metadata plugin support
|
||||
if ($.meta) options = $.extend({}, options, this.data());
|
||||
|
||||
// setup original values
|
||||
this.getFields()
|
||||
.bind('change', function(e) {
|
||||
|
||||
var onchange = function(e) {
|
||||
var $field = $(e.target);
|
||||
var origVal = $field.data('changetracker.origVal');
|
||||
if(origVal === null || $field.val() != origVal) {
|
||||
if(origVal === null || e.target.value != origVal) {
|
||||
// TODO Also add class to radiobutton/checkbox siblings
|
||||
$field.addClass(options.changedCssClass);
|
||||
self.addClass(options.changedCssClass);
|
||||
}
|
||||
})
|
||||
.each(function() {
|
||||
$(this).data('changetracker.origVal', $(this).val());
|
||||
};
|
||||
|
||||
// setup original values
|
||||
var fields = this.getFields();
|
||||
fields.filter(':radio,:checkbox').bind('click', onchange);
|
||||
fields.not(':radio,:checkbox').bind('change', onchange);
|
||||
fields.each(function() {
|
||||
var origVal = $(this).is(':radio,:checkbox') ? self.find(':input[name=' + $(this).attr('name') + ']:checked').val() : $(this).val();
|
||||
$(this).data('changetracker.origVal', origVal);
|
||||
});
|
||||
|
||||
this.data('changetracker', true);
|
||||
|
@ -33,15 +33,14 @@ describe 'ChangeTracker'
|
||||
|
||||
it 'can track changes on input type=radio fields with existing values'
|
||||
$('#form_test').append(
|
||||
'<input type="radio" name="field_radio" value="1" />'
|
||||
+ '<input type="radio" name="field_radio" value="2" />'
|
||||
'<input type="radio" id="field_radio1" name="field_radio" value="1" checked="checked" />'
|
||||
+ '<input type="radio" id="field_radio2" name="field_radio" value="2" />'
|
||||
);
|
||||
|
||||
$('#form_test').changetracker();
|
||||
|
||||
$(':input[name=field_radio]').val(1).trigger('change');
|
||||
$('#field_radio2').attr('checked', 'checked').trigger('click');
|
||||
$('#form_test').is('.changed').should.be_true
|
||||
$(':input[name=field_radio]').is('.changed').should.be_true
|
||||
// $('#field_radio1').is('.changed').should.be_true
|
||||
$('#field_radio2').is('.changed').should.be_true
|
||||
end
|
||||
|
||||
it 'can track changes on select fields with existing values'
|
||||
|
Loading…
Reference in New Issue
Block a user