Page MenuHomePhabricator

SF: validation does not work for new instances of multi-instance templates.
Closed, ResolvedPublic

Description

Author: van.de.bugger

Description:
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.


Version: unspecified
Severity: normal

Details

Reference
bz37231

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 12:30 AM
bzimport set Reference to bz37231.

I should have obviously done this a long time ago, but: reassigning to Stephan, who wrote the JS registration code for form inputs.

@Foxtrott: Do you (still) work (or plan to work) on this issue? If you do not plan to work on this issue anymore, please remove yourself as assignee (via Add Action...Assign / Claim in the dropdown menu) to avoid cookie-licking. Thanks a lot!

Foxtrott subscribed.
Yaron_Koren claimed this task.
Yaron_Koren subscribed.

I just checked this, and it seems to work fine now - I'm guessing this was fixed a few years ago. But I'm glad to finally close this almost-ten-year-old bug! Although feel free to reopen if it's still an issue in any way, of course.