我在表單驗證的rails應用程序中使用了client_side_validations gem,它在提交時添加了一些表單驗證功能,我需要對我自己執行的自定義驗證, client_side_validations gem的功能,所以當我使用form.submit = function
添加它時,它的工作都會被調用。但我不明白如何決定提交表單還是不提交它,如果兩個函數都返回false,那麼它應該提交,但它看起來像即使其中一個返回true,表單也沒有等待提交爲了讓其他人返回它的價值,我如何處理這種情況,我不能把它變成一個函數,因爲這意味着將我的代碼放入client_side_validations JavaScript文件中,我永遠不想這麼做?調用表單中的兩個函數
任何想法和幫助表示讚賞。
這裏是參考
$('#new_business').submit ->
that = $('#business_referrer_code')
if(that.attr("validated") == "true")
return true
else
code = $('#business_referrer_code')
$.ajax '/representatives/validate_code',
type: 'GET'
dataType: 'json'
data: "code=#{code.val()}"
success: (data, textStatus, jqXHR) ->
if(data.error)
that.after("<label class='message'> Invalid Reference Code</label>")
else
that.attr("validated", true)
that.submit()
false
true
其他代碼我自定義的驗證碼是由client_side_validations自動生成的東西我不能改變。
感謝
我們展示的代碼 –
添加的代碼以供參考 – Abid
你可能會不使用.submit,而是使用onclick。正如我所說,根據結果調用提交 –