Forums

Howto call JS validation

fasenderos 29 May, 2015
Hi,
In my form I have many buttons to make some stuff, but only one submit the form. By now the JS validation work only when the form is submitted, I want to add the same (effect/style) of the default js validation also when the other buttons are clicked for ex:

$('#my-button').click(function() {
     if ($('#my-input').val() == ' ') {
     //use the JS validation 'input can't ne empty'
    }
})

Thanks
GreyHead 29 May, 2015
Hi fasenderos,

I'm not clear - do you want:
+ the validation to be run when this button is clicked?
+ to add validation to this input?
+ add matching tool-tips using your own validation code?

I don't know how to do any of these but it might be possible to work it out from the CF validation code

Bob

PS Your code is checking for a space, not an empty input.
fasenderos 29 May, 2015
Hi bob,

PS Your code is checking for a space, not an empty input.


I wrote this code from my smartphone🙂

I'll try to explain.
This is my scenario:

<input type="text" id="test" value="" class="validate['required']">

<input type="button" id="first-button" value="Add">
<input type="submit" id="second-button" value="Submit">

By now if the Submit button is clicked the default JS validation Scroll Up to the field and a Tooltip say "This field is required".

I need to add the same validation (in terms of effect and style) also if the Add button is clicked, maybe by calling the chronoforms API with something like this:

$('#first-button').click(function() {
     if ($('#test').val() == '') {
     //Use the Chronoforms API to validate this field as required so Scrool Up to the field and add the Tooltip that says "This field is required"
    }
})

but it might be possible to work it out from the CF validation code


I know, but It may look different from the one used by CF
Thanks
This topic is locked and no more replies can be posted.