Skip to main content
Correct example
Source Link
Sharky
  • 12k
  • 8
  • 23

For static text use data-validation-text attribute:

<input name="test" class="form-validate validate-test" data-validation-text="Value is invalid">

In case you're using the Form API, use validationtext attribute in the field XML:

<field name="test" type="text" class="form-validate validate-test" validationtext="Value is invalid" />

If you need dynamic text based on value, there is no built-in support for this; validation handlers return only boolean value. You'd have to handle this yourself. One way is to change the data-validation-text attribute in the handler:

document.formvalidator.setHandler('test', function(value, element) {
    if (value.length <=< 5) {
        element.dataset.validationText = 'Username must be at least 5 characters';

        return false;
    }

    if (value.length > 20) {
        element.dataset.validationText = 'Username must be no more than 20 characters';

        return false;
    }

    return true;
});

For static text use data-validation-text attribute:

<input name="test" class="form-validate validate-test" data-validation-text="Value is invalid">

In case you're using the Form API, use validationtext attribute in the field XML:

<field name="test" type="text" class="form-validate validate-test" validationtext="Value is invalid" />

If you need dynamic text based on value, there is no built-in support for this; validation handlers return only boolean value. You'd have to handle this yourself. One way is to change the data-validation-text attribute in the handler:

document.formvalidator.setHandler('test', function(value, element) {
    if (value.length <= 5) {
        element.dataset.validationText = 'Username must be at least 5 characters';

        return false;
    }

    if (value.length > 20) {
        element.dataset.validationText = 'Username must be no more than 20 characters';

        return false;
    }

    return true;
});

For static text use data-validation-text attribute:

<input name="test" class="form-validate validate-test" data-validation-text="Value is invalid">

In case you're using the Form API, use validationtext attribute in the field XML:

<field name="test" type="text" class="form-validate validate-test" validationtext="Value is invalid" />

If you need dynamic text based on value, there is no built-in support for this; validation handlers return only boolean value. You'd have to handle this yourself. One way is to change the data-validation-text attribute in the handler:

document.formvalidator.setHandler('test', function(value, element) {
    if (value.length < 5) {
        element.dataset.validationText = 'Username must be at least 5 characters';

        return false;
    }

    if (value.length > 20) {
        element.dataset.validationText = 'Username must be no more than 20 characters';

        return false;
    }

    return true;
});
Add Form example
Source Link
Sharky
  • 12k
  • 8
  • 23

For static text use data-validation-text attribute:

<input name="test" class="form-validate validate-test" data-validation-text="Value is invalid">

In case you're using the Form API, use validationtext attribute in the field XML:

<field name="test" type="text" class="form-validate validate-test" validationtext="Value is invalid" />

If you need dynamic text based on value, there is no built-in support for this; validation handlers return only boolean value. You'd have to handle this yourself. One way is to change the data-validation-text attribute in the handler:

document.formvalidator.setHandler('test', function(value, element) {
    if (value.length <= 5) {
        element.dataset.validationText = 'Username must be at least 5 characters';

        return false;
    }

    if (value.length > 20) {
        element.dataset.validationText = 'Username must be no more than 20 characters';

        return false;
    }

    return true;
});

For static text use data-validation-text attribute:

<input name="test" class="form-validate validate-test" data-validation-text="Value is invalid">

If you need dynamic text based on value, there is no built-in support for this; validation handlers return only boolean value. You'd have to handle this yourself. One way is to change the data-validation-text attribute in the handler:

document.formvalidator.setHandler('test', function(value, element) {
    if (value.length <= 5) {
        element.dataset.validationText = 'Username must be at least 5 characters';

        return false;
    }

    if (value.length > 20) {
        element.dataset.validationText = 'Username must be no more than 20 characters';

        return false;
    }

    return true;
});

For static text use data-validation-text attribute:

<input name="test" class="form-validate validate-test" data-validation-text="Value is invalid">

In case you're using the Form API, use validationtext attribute in the field XML:

<field name="test" type="text" class="form-validate validate-test" validationtext="Value is invalid" />

If you need dynamic text based on value, there is no built-in support for this; validation handlers return only boolean value. You'd have to handle this yourself. One way is to change the data-validation-text attribute in the handler:

document.formvalidator.setHandler('test', function(value, element) {
    if (value.length <= 5) {
        element.dataset.validationText = 'Username must be at least 5 characters';

        return false;
    }

    if (value.length > 20) {
        element.dataset.validationText = 'Username must be no more than 20 characters';

        return false;
    }

    return true;
});
Source Link
Sharky
  • 12k
  • 8
  • 23

For static text use data-validation-text attribute:

<input name="test" class="form-validate validate-test" data-validation-text="Value is invalid">

If you need dynamic text based on value, there is no built-in support for this; validation handlers return only boolean value. You'd have to handle this yourself. One way is to change the data-validation-text attribute in the handler:

document.formvalidator.setHandler('test', function(value, element) {
    if (value.length <= 5) {
        element.dataset.validationText = 'Username must be at least 5 characters';

        return false;
    }

    if (value.length > 20) {
        element.dataset.validationText = 'Username must be no more than 20 characters';

        return false;
    }

    return true;
});