我有一个带有两个按钮的羊驼毛形式:“保存草稿”和“提交”。我正在尝试为这些按钮实现的行为是:
- 即使没有必填字段或其他验证问题,用户也可以单击“保存草稿”按钮并提交表单;他们的数据将被保存,以便以后可以在表单上继续工作;它们的部分数据返回时将存储在后端,并以
data
数组的形式包含。 - “提交”按钮的行为正常;在表单验证之前,它将保持禁用状态。他们的最终提交数据将存储在后端,标记为已完成并锁定。
official documentation about validation有点稀疏,似乎暗示可能有必要向表单上的每个字段添加自定义验证器,但是我希望可以有一种更简单的方法;我正在想象“保存草稿”按钮的自定义onClick
行为,例如
onClick="function(){$('#form').alpaca('get').justMarkTheWholeFormValidAndGo()}"
我一直在尝试使用基本的“入门”示例表单来完成这项工作:
$("#form").alpaca({
"data": {
},"schema": {
"title": "User Feedback","description": "What do you think about Alpaca?","type": "object","properties": {
"name": {
"type": "string","title": "Name","required": true
},"feedback": {
"type": "string","title": "Feedback"
},"ranking": {
"type": "string","title": "Ranking","enum": ["excellent","ok","so so"],}
},"options": {
"form": {
"attributes": {
"action": "/path/to/submission/handler/","method": "post"
},"buttons": {
"save_draft": {
"type": "submit","value": "Save Draft","attributes": {
"name": "safe_draft"
}
},"submit": {
"type": "submit","value": "Submit","attributes": {
"name": "submit"
}
}
}
},"helper": "Tell us what you think about Alpaca!","fields": {
"name": {
"size": 20,"helper": "Please enter your name."
},"feedback": {
"type": "textarea","rows": 5,"cols": 40,"helper": "Please enter your feedback."
},"ranking": {
"type": "select","helper": "Select your ranking.","optionLabels": ["Awesome!","It's Ok","Hmm..."]
},},"hideInitValidationError": true
}
});