nv-validator-radio
v1.0.3
Published
nv-validator-radio =============== - nv-validator-radio is a simple util to simulate radio-select
Downloads
4
Readme
nv-validator-radio
- nv-validator-radio is a simple util to simulate radio-select
install
- npm install nv-validator-radio
usage
example
const radio = require("nv-validator-radio");
const vali = require("nv-validator-engine")
function percent_value_validator_func(v,...other_args) {
if(v<0) {
return(("value must >=0"))
} else if(v<=100) {
return(v.toString()+"%")
} else {
return(new Error("value must <=100"))
}
}
function px_value_validator_func(v,...other_args) {
if(v<0) {
return(("value must >=0"))
} else if(v<=2000) {
return(v.toString()+"px")
} else {
return(new Error("value must <=2000"))
}
}
//create options
var percent = vali.creat_value_validator("percent",percent_value_validator_func)
var px = vali.creat_value_validator("px",px_value_validator_func)
//creat radio select
var Length = radio.creat_radio_cls('length')
var length = new Length()
//add options to radio select
length.proxy.percent = percent
length.proxy.px = px
//select one
length.percent(50)
> length.val()
'50%'
//change selected
> length.px(50)
'50px'
> length.val()
'50px'
>
//unset all
> length.unset()
> length.percent.val()
undefined
> length.px.val()
undefined
> length.val()
undefined
API
- radio.creat_radio_cls(pkey)
LICENSE
- ISC