[英]How to validate decimal fields in semantic-ui?
在語義UI中,可以驗證十進制數字嗎? 對於整數,可以輕松設置:
$('.ui.form')
.form({
fields: {
field1: {
rules: [
{
type : 'integer[1..20]',
}
]
},
....
並且只有在落入指定范圍內時才對整數進行驗證。 對於十進制輸入,我需要做同樣的事情(需要落在1.99-100.99的范圍內),但是用於整數的相同方法似乎不起作用。
我該如何實現? 謝謝。
我這樣解決了這個問題:
$(document).ready(function() {
$.fn.form.settings.rules.greaterThan = function (inputValue, validationValue) {
return inputValue >= validationValue;
};
$.fn.form.settings.rules.smallerThan = function (inputValue, validationValue) {
return inputValue <= validationValue;
}
$('.ui.form')
.form({
on: 'blur',
fields: {
decimal: {
rules: [
{
type : 'decimal',
prompt : 'Please enter a decimal number here'
},
{
type: 'greaterThan[1.99]',
prompt: 'The price should be greater than 1.99',
},
{
type: 'smallerThan[100.99]',
prompt: 'The price should be less than 100.99',
},
]
},
}
})
;
});
這樣,您將驗證結合在一起以獲得所需結果的三個規則。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.