Taiga 前端即使无效也提交自定义属性更改
Taiga front end submits custom attribute changes even if invalid
我目前正在开发 taiga 的自定义实现,我注意到,即使我们在 app/partials/custom-attributes/custom-attribute-value-edit.jade
中为自定义输入字段放置了一个模式,如果输入不符合像这样指定的模式
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 %>")
表单仍然提交到后端。虽然我确实看到一条快速消息说模式不匹配,但表格仍已提交。我跟踪过程最远的是这个文件
app/coffee/modules/common/custom-field-values.coffee
那里有一个部分用于处理提交
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")
但就我所知。我的目标是如果存在输入验证问题(例如输入不遵循指定模式),则不允许提交发生。我使用的是 taiga 的当前版本 3.0.0
我终于明白了。 Taiga 使用 checksley 进行表单验证。我没有像普通输入字段验证器那样对正则表达式使用 "pattern",而是使用了 checksley 的属性数据正则表达式。这处理了我需要的验证。
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 %>")
文档可以在下面找到link
https://media.readthedocs.org/pdf/checksley/latest/checksley.pdf
我目前正在开发 taiga 的自定义实现,我注意到,即使我们在 app/partials/custom-attributes/custom-attribute-value-edit.jade
中为自定义输入字段放置了一个模式,如果输入不符合像这样指定的模式
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 %>")
表单仍然提交到后端。虽然我确实看到一条快速消息说模式不匹配,但表格仍已提交。我跟踪过程最远的是这个文件
app/coffee/modules/common/custom-field-values.coffee
那里有一个部分用于处理提交
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")
但就我所知。我的目标是如果存在输入验证问题(例如输入不遵循指定模式),则不允许提交发生。我使用的是 taiga 的当前版本 3.0.0
我终于明白了。 Taiga 使用 checksley 进行表单验证。我没有像普通输入字段验证器那样对正则表达式使用 "pattern",而是使用了 checksley 的属性数据正则表达式。这处理了我需要的验证。
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 %>")
文档可以在下面找到link
https://media.readthedocs.org/pdf/checksley/latest/checksley.pdf