Closed nilskp closed 12 years ago
What do you mean? Can you elaborate a bit more?
I want to submit a form, and on an error response from server, be able to highlight the fields in error. It doesn't look like I can do that today. It seems I can only do custom regex validation and form errors only pop up once I've entered the field. That wouldn't work for server validated fields.
Ideal Forms is all about live validation or "on the spot" as I like to call it. You can do an AJAX request within a custom filter. If the filter returns false
then it fails validation and it shows your error; if it returns true
then it passes. The filter will run the request "on the spot" and inform you through the error message.
var myFilter = {
regex: function( input, value ) {
var isValid = false
$.post(
'script.php',
{ value: value },
function( data ) {
// make sure to receive JSON from PHP with json_encode
isValid = $.parseJSON(data)
}
)
return isValid
},
error: 'Something went wrong...'
}
// Add filter to Ideal Forms
$.extend( $.idealforms.filters, myFilter )
If what you want to do is double check the values from client side then when a value is not correct you can just reset the field and then focus the field to show the error.
$myform.reset(['foo'])
$('input[name=foo]').trigger('focus')
I didn't see a way to invoke errors on external validation, such as server side validation. This would be nice.