1
0
Fork 0

Minor StepUi cleanup

master
Mike Gerwitz 2015-11-30 11:43:28 -05:00
parent 215869e1ea
commit 1c4554dd0d
1 changed files with 31 additions and 14 deletions

View File

@ -211,7 +211,7 @@ module.exports = Class( 'StepUi' )
_self._hookBucket(); _self._hookBucket();
_self._processAnswerFields(); _self._processAnswerFields();
_self.invalidate(); _self.invalidate();
}); } );
return this; return this;
}, },
@ -288,14 +288,15 @@ module.exports = Class( 'StepUi' )
/** /**
* Will mark the step as dirty when the content is changed and update the * Will mark the step as dirty when the content is changed and update
* staging bucket * the staging bucket
* *
* @return undefined * @return undefined
*/ */
setDirtyTrigger: function() setDirtyTrigger: function()
{ {
var step = this; var step = this;
this.$content.bind( 'change.program', function( event ) this.$content.bind( 'change.program', function( event )
{ {
// do nothing if the step is locked // do nothing if the step is locked
@ -328,34 +329,46 @@ module.exports = Class( 'StepUi' )
{ {
index = 0; index = 0;
} }
else if ( $element.attr( 'type' ) === 'radio' || $element.attr( 'type' ) === 'checkbox' ) else if ( $element.attr( 'type' ) === 'radio'
|| $element.attr( 'type' ) === 'checkbox'
)
{ {
// if it's not checked, then this isn't the radio we're // if it's not checked, then this isn't the radio we're
// interested in. Sorry! // interested in. Sorry!
if ( !( $element.attr( 'checked' ) ) ) if ( !( $element.attr( 'checked' ) ) )
{ {
$element.attr( 'checked', true ) $element.attr( 'checked', true );
return; return;
} }
// 2 in this instance is the yes/no group length. // 2 in this instance is the yes/no group length.
var group_length = $element.attr( 'data-question-length' ) ? $element.attr( 'data-question-length' ) : 2; var group_length = $element.attr( 'data-question-length' )
? $element.attr( 'data-question-length' )
: 2;
index = Math.floor( index / group_length ); index = Math.floor( index / group_length );
} }
var values = {}; var values = {};
values[name] = []; values[ name ] = [];
values[name][index] = val; values[ name ][ index ] = val;
// update our bucket with this new data // update our bucket with this new data
step.emit( step.__self.$('EVENT_DATA_CHANGE'), values ); step.emit( step.__self.$('EVENT_DATA_CHANGE'), values );
}); } );
// @note This is a hack. In IE8, checkbox change events don't properly fire. // @note This is a hack. In IE8, checkbox change events don't properly fire.
this.$content.delegate('input[type="checkbox"]', 'click', function () { jQuery(this).change(); } ); this.$content.delegate(
'input[type="checkbox"]',
'click',
function ()
{
// XXX: remove global
jQuery( this ).change();
}
);
}, },
@ -630,7 +643,7 @@ module.exports = Class( 'StepUi' )
); );
} }
} }
}); } );
}, },
@ -802,11 +815,15 @@ module.exports = Class( 'StepUi' )
*/ */
'public getFirstInvalidField': function( cmatch ) 'public getFirstInvalidField': function( cmatch )
{ {
var $element = this.$content.find( '.invalid_field[data-field-name]:visible:first' ); var $element = this.$content.find(
'.invalid_field[data-field-name]:visible:first'
);
if ( $element.length === 0 ) if ( $element.length === 0 )
{ {
$element = this.$content.find( '.invalid_field[data-field-name]:first' ); $element = this.$content.find(
'.invalid_field[data-field-name]:first'
);
} }
var name = $element.attr( 'data-field-name' ); var name = $element.attr( 'data-field-name' );