Новости | FAQ | Авторы | Документация | В действии | Библиотека |
Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
Азат Разетдинов 18.05.2007 18:47
@CLASS WebForms @USE Node.p @auto[] $FIELD[field] $MATCHES[ $.date[\d{4}-\d{2}-\d{2}] $.month[\d{4}-\d{2}] $.week[\d{4}-W\d{2}] $.time[\d{4}:\d{2}(?::\d{2}(?:\.\d+)?)?] $.url[(?:[a-z]+://)?[:\w~%{}./?=&@,#-]+] $.number[-?\d+(?:\.\d+)?(?:e\d+)?] ] ^MATCHES.add[ $.range[$MATCHES.number] $.datetime[${MATCHES.date}T${MATCHES.time}Z] $.datetime-local[${MATCHES.date}T$MATCHES.time] ] #end @auto[] @checkValidity[xForm][hNodes;xNode] $hNodes[^xForm.select[//${FIELD}[ not(@readonly or @disabled or ancestor-or-self::*[@willValidate=0]) ]]] ^hNodes.foreach[;xNode]{^checkNode[$xNode]} $result(^xForm.selectBool[not(//${FIELD}[@valid = 0])]) #end @checkValidity[] @checkNode[xNode][k;v;hError;hAttr] $hError[^hash::create[]] $hAttr[^Node:getAttributes[$xNode]] ^if(def $hAttr.value){ ^if( def $MATCHES.[$hAttr.type] && !^hAttr.value.match[^^(?:$MATCHES.[$hAttr.type])^$] ){ ^hError.add[$.typeMismatch[1]] } ^if(!$hError.typeMismatch){ ^switch[$hAttr.type]{ ^case[email]{ ^use[Lib.p] ^if(!^Lib:isEmail[$hAttr.value]){ ^hError.add[$.typeMismatch[1]] } } ^case[number;range]{ ^if( ^hAttr.min.double(0) && ^hAttr.value.double(0) < ^hAttr.min.double(0) ){ ^hError.add[$.rangeUnderFlow[1]] } ^if( ^hAttr.max.double(0) && ^hAttr.value.double(0) > ^hAttr.max.double(0) ){ ^hError.add[$.rangeOverFlow[1]] } } ^case[date;time;datetime;datetime-local]{ ^if(def $hAttr.min && $hAttr.value lt $hAttr.min){ ^hError.add[$.rangeUnderFlow[1]] } ^if(def $hAttr.max && $hAttr.value gt $hAttr.max){ ^hError.add[$.rangeOverFlow[1]] } } } } ^if( ^hAttr.maxlength.int(0) && ^hAttr.value.length[] > ^hAttr.maxlength.int(0) ){ ^hError.add[$.tooLong[1]] } ^if(def $hAttr.pattern){ ^try{ ^if(!^hAttr.value.match[^^(?:$hAttr.pattern)^$]){ ^hError.add[$.patternMismatch[1]] } }{ $exception.handled(true) } } }{ ^if(def $hAttr.required){ ^hError.add[$.valueMissing[1]] } } ^if(def $hAttr.customError){ ^hError.add[$.customError[1]] } ^xNode.setAttribute[valid;^if(!$hError){1;0}] ^hError.foreach[k;v]{ ^xNode.setAttribute[$k;$v] } $result[] #end @checkNode[]