3

I have problem with Mootools formcheck js when applying custom function to Selectbox field. Custom Function will be work fine with Text Field, but Selectbox is NOT.

My dummy code of Custom Function:

var customFunc = function customFuncF(el) {
    el.errors.push('Custom function!!!');
    return false;
};

And There are a simple form that I apply to a text field:

enter image description here

and

<input type="text" class="validate['%customFunc']" id="User_lastName" name="User[lastName]" >

-> It works fine with text field.

But when I apply custom function to Selectbox field, example as Office list in my simple form, it's seems not work and always returns true. My example code for Selectbox

<select id="User_officeId" class="validate['%customFunc']" name="User[officeId]" >
    <option selected="selected" value="">-Select Office-</option>
    <option value="1">Office A</option>
    <option value="2">Office B</option>
</select>

How can I apply custom function to Selectbox field?

Thanks,

dakiquang
  • 684
  • 1
  • 8
  • 24
  • Could you be more specific on which version of formcheck you are using and make a jsFiddle with a example of your problem? And also, does it have to work on MooTools 1.2? – Sergio Jul 14 '14 at 07:46
  • @Sergio Version of formcheck is 1.6 with mootools 1.2.1. I'll post it in jsFiddle soon – dakiquang Jul 16 '14 at 02:41
  • did you manage to get the fiddle together? – Sergio Jul 23 '14 at 18:04

1 Answers1

0

It was caused by your validate which excludes the keyword 'required'. In fact, the custom function works.

But in function 'manageError':

manageError : function(el, method) {
    ...
    } else if ((isValid || (!el.validation.contains('required') && !el.value))) {
        this.removeError(el);
        return true;
    }
    return true;
},

As no 'required' and no value in here, the pushed error was be removed. :(

You can add the word 'required' into validate[] or setup the value of first option to 0 instead of blank.

bigonez
  • 111
  • 2