Sleepness/UberFrontendValidationBundle

View on GitHub
Resources/public/js/constraints/True.js

Summary

Maintainability
B
4 hrs
Test Coverage
/**
 * Check if element value is true
 *
 * @author Viktor Novikov <viktor.novikov95@gmail.com>
 * @constructor
 */
function UberTrueValidationConstraint(field) {
    this.message = 'Value of {{ field_name }} should be TRUE.';

    this.validate = function () {
        var error = '';
        if (!field.val()) return error;

        error = this.message.replace('{{ field_name }}', String(parse_field_name(field.attr('name'))));
        if (field.attr('data-message-true') !== '') {
            error = field.attr('data-message-true');
        }

        return error;
    };
}