Новости | FAQ | Авторы | Документация | В действии | Библиотека |
Инструменты | Полезные ссылки | Хостинги | Скачать | Примеры | Форум |
Азат Разетдинов 18.05.2007 17:35
1. Добавил поддержку min/max (выдаются флаги rangeUnderFlow и rangeOverFlow).@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][bIsValid;hAttr] $bIsValid(true) $hAttr[^Node:getAttributes[$xNode]] ^if(def $hAttr.value){ ^if( def $MATCHES.[$hAttr.type] && !^hAttr.value.match[^^(?:$MATCHES.[$hAttr.type])^$] ){ ^xNode.setAttribute[typeMismatch;1] $bIsValid(false) } ^if($bIsValid){ ^switch[$hAttr.type]{ ^case[email]{ ^use[Lib.p] ^if(!^Lib:isEmail[$hAttr.value]){ ^xNode.setAttribute[typeMismatch;1] $bIsValid(false) } } ^case[number;range]{ ^if( ^hAttr.min.double(0) && ^hAttr.value.double(0) < ^hAttr.min.double(0) ){ ^xNode.setAttribute[rangeUnderFlow;1] $bIsValid(false) } ^if( ^hAttr.max.double(0) && ^hAttr.value.double(0) > ^hAttr.max.double(0) ){ ^xNode.setAttribute[rangeOverFlow;1] $bIsValid(false) } } ^case[date;time;datetime;datetime-local]{ ^if(def $hAttr.min && $hAttr.value lt $hAttr.min){ ^xNode.setAttribute[rangeUnderFlow;1] $bIsValid(false) } ^if(def $hAttr.max && $hAttr.value gt $hAttr.max){ ^xNode.setAttribute[rangeOverFlow;1] $bIsValid(false) } } } } ^if( ^hAttr.maxlength.int(0) && ^hAttr.value.length[] > ^hAttr.maxlength.int(0) ){ ^xNode.setAttribute[tooLong;1] $bIsValid(false) } ^if(def $hAttr.pattern){ ^try{ ^if(!^hAttr.value.match[^^(?:$hAttr.pattern)^$]){ ^xNode.setAttribute[patternMismatch;1] $bIsValid(false) } }{ $exception.handled(true) } } }{ ^if(def $hAttr.required){ ^xNode.setAttribute[valueMissing;1] $bIsValid(false) } } ^if(def $hAttr.customError){ $bIsValid(false) } ^xNode.setAttribute[valid;^if($bIsValid){1;0}] $result[] #end @checkNode[]