類似於this question和this question我無法弄清楚如何在綁定單個字段時使用Javascript配置Parsley自定義遠程。如何使用javascript配置荷蘭芹自定義遠程,而不是屬性
例如我想(簡體):
$('#field').parsley({
remote: true,
remoteValidator: 'mycustom';
});
是的the example相當於:
<input name="q" type="text" data-parsley-remote data-parsley-remote-validator='mycustom' value="foo" />
我已經註冊的遠程之後的例子:
window.Parsley.addAsyncValidator('mycustom', function (xhr) {
console.log(this.$element);
return 404 === xhr.status;
}, '/api/foo');
當這個執行香菜也嘗試處理內部遙控器內部的遙控功能:
validateString: function validateString(value, url, options, instance) {
雖然Parsley.asyncValidators
確實包括mycustom
遠程確定,options
參數不是我希望的選項(它是歐芹場本身擁有這些選項爲options
屬性)。因此options.validator
在此上下文中爲空,因此該方法選擇默認值,該值未配置,因此它在url.indexOf
上出錯。無論如何,如果我錯誤地配置了它,這可能都是不相關的。
我已經瀏覽了文檔,示例和源代碼,但無法弄清楚如何從配置中讀取這些值。
更新:我通過鮑爾安裝它,並使用dist/parsely.min.js。我看不到在建築的任何地方parsely.remote.js(在文檔中提到),所以我認爲它的全部編譯。
奇數,'remote:true'也應該有效。 –
PS:要獲得歐芹字段的選項,只需使用'$('#field')。parsley()。options' –
雖然.options方法是垃圾進出垃圾。它只是返回我放入的內容。 – scipilot