Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Working on a B-tree form. Reply To: Working on a B-tree form.

#183649
__
Participant

Or would you put the validation logic in this function?

Yes, the plan was to add a validation property to each branch object which would control validating the fields on the current branch before allowing the user to move on. I already made a place for this to hook into:

// if there is validation to be done, only continue if it is successful
if( branch[currentState].validation && ! branch[currentState].validation() ){
    return;
}

The assumption was that the validation function would return true if everything passed (and the handler would go ahead an switch to the next branch), or it would return false and we would just stop. If there was anything that needed to be done (error messages, etc.), the validation function would do (or more likely, dispatch) them.

Is this for purposes of event delegation?

Yes, this hooks up click events on the form to the stateHandler function (which only does something if the click was on one of the navigation buttons —specifically, a [data-next] button).