javascriptcoffeescripttaiga

Taiga front end submits custom attribute changes even if invalid


I'm currently working on a custom implementation of taiga and i noticed that, even if we placed a pattern for our custom input field in app/partials/custom-attributes/custom-attribute-value-edit.jade to ping an error if the input doesn't follow the specified pattern like so

input#custom-field-value(name="value", type="tel", pattern="^\\+\\d{1,3}\\s\\d{1,3}\\s\\d{3}\\s\\d{4}$", placeholder="format: +[country_code] [area_code] [xxx] [xxxx] (e.g: +1 234 567 8910)", value!="<%- value %>")

the form is still submitted to the back-end. although i do see a quick message saying that the pattern doesn't match, the form is still submitted. the farthest i got to tracing the process was to this file app/coffee/modules/common/custom-field-values.coffee

there's a part there for processing the submit

    submit = debounce 2000, (event) =>
        event.preventDefault()

        form = $el.find("form").checksley()
        return if not form.validate()

        input = $el.find("input[name=value], textarea[name='value'], select[name='value']")
        attributeValue.value = input.val()
        if input.prop("type") == 'checkbox'
            if input[0].checkValidity()
                attributeValue.value = !!input.prop("checked")

but that's as far as i got. my goal is to not allow the submit to occur if there are input validation issues like the input not following the specified pattern. I'm using the current version of taiga which is 3.0.0


Solution

  • I figured it out eventually. Taiga uses checksley for form validation. instead of using "pattern" for my regular expression like a normal input field validator, i used checksley's attribute data-regexp. This handled the validation that i needed.

    input#custom-field-value(name="value", type="tel", data-regexp="^\\+\\d{1,3}\\s\\d{1,3}\\s\\d{3}\\s\\d{4}$", placeholder="format: +[country_code] [area_code] [xxx] [xxxx] (e.g: +1 234 567 8910)", value!="<%- value %>")
    

    the documentation can be found in the following link

    https://media.readthedocs.org/pdf/checksley/latest/checksley.pdf