Last modified: 2014-02-12 23:38:01 UTC
SemanticForms 2.4.1. I have implemented a new input type. My type has validation function but does not have initialization function: > // NOT CALLED: $this->addJsInitFunctionData( 'mytype.init' ); > $this->addJsValidationFunctionData( 'mytype.validate' ); Everything works ok, but new instances of multi-instance template are not validated. The problem is in SemanticForms.js file, line ~ 867: > var sfdata = jQuery("#sfForm").data('SemanticForms'); > if ( sfdata && sfdata.initFunctions[old_id] ) { // found data object? > // For every initialization method for > // input with id old_id, register the > // method for the new input. > for ( var i = 0; i < sfdata.initFunctions[old_id].length; i++ ) { > jQuery(this).SemanticForms_registerInputInit( > sfdata.initFunctions[old_id][i].initFunction, > sfdata.initFunctions[old_id][i].parameters, > true //do not yet execute > ); > } > // For every validation method for the > // input with ID old_id, register it > // for the new input. > for ( var i = 0; i < sfdata.validationFunctions.length; i++ ) { > if ( sfdata.validationFunctions[i].input == old_id ) { > jQuery(this).SemanticForms_registerInputValidation( > sfdata.validationFunctions[i].valfunction, > sfdata.validationFunctions[i].parameters > ); > } > } > } Yo see, that registering both initialization and validation functions are under the same condition -- if initialization function exist. I think it would be better to decouple it, so validation works regardless of initialization.
I should have obviously done this a long time ago, but: reassigning to Stephan, who wrote the JS registration code for form inputs.