qForms, библиотека типичного функционала валидации/построения/связки html-форм
реализации: javascript, количество: 11
реализации(исходники)
+добавить
В данной задаче для свободного анализа и обсуждения выкладываются исходники известной javascript-библиотеки qForms(www.pengoworks.com).
Данная библиотека инкапсулирует, реализует основные типичные процедуры задач валидации, динамического связывания, построения елементов html-форм.
Реализации: javascript(11) +добавить реализацию
заполните необходимые поля!
1) Фрагмент-пример использования, code #160[автор:-]
Пример использования qForms (api 139), javascript, code #160
ссылка
+
рейтинг: 3/7,4.87(3029), управление:
рейтинг: 3/7,4.87(3029), управление:
<HEAD> ........ <!--// load the qForm JavaScript API //--> <SCRIPT SRC="../../lib/qforms.js"></SCRIPT> <SCRIPT LANGUAGE="JavaScript"> <!--// // set the path to the qForms directory qFormAPI.setLibraryPath("../../lib/"); // this loads all the default libraries qFormAPI.include("*"); //--> </SCRIPT> </HEAD> <body> <!--// ..... Form Html ....... //--> <!--// ..... qForms Code Form Binding >> ....... //--> <SCRIPT LANGUAGE="JavaScript"> <!--// // initialize the qForm object objForm = new qForm("frmExample"); // make these fields required objForm.required("Name, Email"); // force validation to occur on the "onBlur" events objForm.forceValidation("Name, Email"); // make sure the "Name" field is not left empty objForm.Name.validateNotEmpty(); // make sure the "Email" field appears syntatically correct objForm.Email.validateEmail(); //--> </body>
Здесь показываются 2 из многочисленных простых задач, реализованных в этой библиотеке: валидация формы на пустоту заполнения элементов + на правильность заполнения
Тестировалось на: IE 6.0 SP2, Mozilla FF 1.5, Opera 8.5

3) bits.js :: qForms api-139, code #151[автор:-]
bits.js библиотечный файл :: qForms api-139, javascript, code #151
ссылка
+
рейтинг: 3/7,4.89(3038), управление:
рейтинг: 3/7,4.89(3038), управление:
// define Field getBits(); prototype function _Field_getBits(useValue){ var isCheckbox = (this.type == "checkbox") ? true : false; var isSelect = (this.type == "select-multiple") ? true : false; if( !isCheckbox && !isSelect && (this.obj.length > 0) ) return alert("This method is only available to checkboxes or select boxes with multiple options."); var useValue = _param(arguments[0], false, "boolean"); var iBit = 0; // loop through all checkbox elements, and if a checkbox is checked, grab the value for( var i=0; i < this.obj.length; i++ ){ // if the option is checked, then add the 2 ^ i to the existing value if( isCheckbox && this.obj[i].checked ){ // append the selected value iBit += (useValue) ? parseInt(this.obj[i].value, 10) : Math.pow(2, i); } else if( isSelect && this.obj.options[i].selected ){ iBit += (useValue) ? parseInt(this.obj[i].value, 10) : Math.pow(2, i); } } return iBit; } Field.prototype.getBits = _Field_getBits; // define Field setBits(); prototype function _Field_setBits(value, useValue){ var isCheckbox = (this.type == "checkbox") ? true : false; var isSelect = (this.type == "select-multiple") ? true : false; if( !isCheckbox && !isSelect && (this.obj.length > 0) ) return alert("This method is only available to checkboxes or select boxes with multiple options."); var value = _param(arguments[0], "0"); var useValue = _param(arguments[1], false, "boolean"); var value = parseInt(value, 10); // loop through all checkbox elements, and if a checkbox is checked, grab the value for( var i=0; i < this.obj.length; i++ ){ // if the bitand returns the same as the value being checked, then the current // checkbox should be checked var j = (useValue) ? parseInt(this.obj[i].value, 10) : Math.pow(2, i); var result = ( (value & j) == j) ? true : false; if( isCheckbox ) this.obj[i].checked = result; else if( isSelect ) this.obj.options[i].selected = result; } // if the value provided is greater then the last bit value, return false to indicate an error // otherwise return true to say everything is ok return (value < Math.pow(2, i)) ? true : false; } Field.prototype.setBits = _Field_setBits;
/******************************************************************************
qForm JSAPI: Bits Extensions Library
Author: Dan G. Switzer, II
Build: 101
******************************************************************************/
qForm JSAPI: Bits Extensions Library
Author: Dan G. Switzer, II
Build: 101
******************************************************************************/
Тестировалось на: IE 6.0 SP2, Mozilla FF 1.5, Opera 8.5

5) cookies.js :: qForms api-139, code #153[автор:-]
cookies.js библиотечный файл :: qForms api-139, javascript, code #153
ссылка
+
рейтинг: 3/7,4.83(2992), управление:
рейтинг: 3/7,4.83(2992), управление:
// initialize workspace variables var _c_dToday = new Date(); var _c_iExpiresIn = 90; var _c_strName = self.location.pathname; /****************************************************************************** Required Functions ******************************************************************************/ // retrieve a cookie from the browser function _getCookie(name){ var iStart = document.cookie.indexOf(name + "="); var iLength = iStart + name.length + 1; if( (iStart == -1) || (!iStart && (name == document.cookie.substring(0)) ) ) return null; var iEnd = document.cookie.indexOf(";", iLength); if( iEnd == -1 ) iEnd = document.cookie.length; return unescape(document.cookie.substring(iLength, iEnd)); } // set a cookie to the browser function _setCookie(name, value, expires, path, domain, secure){ document.cookie = name + "=" + escape(value) + ( (expires) ? ";expires=" + expires.toGMTString() : "") + ( (path) ? ";path=" + path : "") + ( (domain) ? ";domain=" + domain : "") + ( (secure) ? ";secure" : ""); } function _deleteCookie(name, path, domain){ if (Get_Cookie(name)) document.cookie = name + "=" + ( (path) ? ";path=" + path : "") + ( (domain) ? ";domain=" + domain : "") + ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; } function _createCookiePackage(struct){ var cookie = ""; for( key in struct ){ if( cookie.length > 0 ) cookie += "&"; cookie += key + ":" + escape(struct[key]); } return cookie; } function _readCookiePackage(pkg){ struct = new Object(); // break the package into key/value pairs var a = pkg.split("&"); // loop through the array and seperate the key/value pairs for( var i=0; i < a.length; i++ ) a[i] = a[i].split(":"); // convert the values into a structure for( var i=0; i < a.length; i++ ) struct[a[i][0]] = unescape(a[i][1]); // return the structure return struct; } /****************************************************************************** qForm Methods ******************************************************************************/ // define qForm loadFields(); prototype function _qForm_loadFields(){ var strPackage = _getCookie("qForm_" + this._name + "_" + _c_strName); // there is no form saved if( strPackage == null ) return false; this.setFields(_readCookiePackage(strPackage), null, true); } qForm.prototype.loadFields = _qForm_loadFields; // define qForm saveFields(); prototype function _qForm_saveFields(){ var expires = new Date(_c_dToday.getTime() + (_c_iExpiresIn * 86400000)); var strPackage = _createCookiePackage(this.getFields()); _setCookie("qForm_" + this._name + "_" + _c_strName, strPackage, expires); } qForm.prototype.saveFields = _qForm_saveFields; // define qForm saveOnSubmit(); prototype function _qForm_saveOnSubmit(){ // grab the current onSubmit() method and append the saveFields() method to it var fn = _functionToString(this.onSubmit, "this.saveFields();"); this.onSubmit = new Function(fn); } qForm.prototype.saveOnSubmit = _qForm_saveOnSubmit;
/******************************************************************************
qForm JSAPI: Cookie Library
Author: Dan G. Switzer, II
Build: 105
******************************************************************************/
qForm JSAPI: Cookie Library
Author: Dan G. Switzer, II
Build: 105
******************************************************************************/
Тестировалось на: IE 6.0 SP2, Mozilla FF 1.5, Opera 8.5

7) functions.js :: qForms api-139, code #155[автор:-]
8) functions_js12.js :: qForms api-139, code #156[автор:-]
9) validation.js :: qForms api-139, code #157[автор:-]
10) validation_addon.js :: qForms api-139, code #158[автор:-]
validation_addon.js библиотечный файл :: qForms api-139, javascript, code #158
ссылка
+
рейтинг: 3/7,4.81(3419), управление:
рейтинг: 3/7,4.81(3419), управление:
qFormAPI.packages.validation = true; // [start] validation routine function _f_isAtLeastOne(_f){ var sFields = this.name + ((typeof _f == "string") ? "," + _removeSpaces(_f) : ""); var aFields = sFields.split(","), v = new Array(), d = new Array(), x = ","; for( var i=0; i < aFields.length; i++ ){ if( !this.qForm[aFields[i]] ) return alert("The field name \"" + aFields[i] + "\" does not exist."); // store the value in an array v[v.length] = this.qForm[aFields[i]].getValue(); // if the field name is already in the list, don't add it if( x.indexOf("," + aFields[i] + ",") == -1 ){ d[d.length] = this.qForm[aFields[i]].description; x += aFields[i] + ","; } } // if all of the form fields has empty lengths, then throw // an error message to the page if( v.join("").length == 0 ){ this.error = "At least one of the following fields is required:\n " + d.join(", "); for( i=0; i < aFields.length; i++ ){ if( qFormAPI.useErrorColorCoding && this.qForm[aFields[i]].obj.style ) this.qForm[aFields[i]].obj.style[qFormAPI.styleAttribute] = qFormAPI.errorColor; } } } _addValidator("isAtLeastOne", _f_isAtLeastOne, true);
/******************************************************************************
qForm JSAPI: Add-on Validation Library
Author: Dan G. Switzer, II
Build: 100
******************************************************************************/
qForm JSAPI: Add-on Validation Library
Author: Dan G. Switzer, II
Build: 100
******************************************************************************/
Тестировалось на: IE 6.0 SP2, Mozilla FF 1.5, Opera 8.5

wddx.js библиотечный файл :: qForms api-139, javascript, code #159
ссылка
+
рейтинг: 3/7,4.85(3232), управление:
рейтинг: 3/7,4.85(3232), управление:
/****************************************************************************** Required Functions ******************************************************************************/ function __serializeStruct(struct){ // open packet var aWDDX = new Array("<wddxPacket version='1.0'><header/><data><struct>"); for( var key in struct ) aWDDX[aWDDX.length] = "<var name='" + key.toLowerCase() + "'><string>" + __wddxValue(struct[key]) + "</string></var>"; // close packet aWDDX[aWDDX.length] = "</struct></data></wddxPacket>"; return aWDDX.join(""); } function __wddxValue(str){ var aValue = new Array(); for( var i=0; i < str.length; ++i) aValue[aValue.length] = _encoding.table[str.charAt(i)]; return aValue.join(""); } function _wddx_Encoding(){ // Encoding table for strings (CDATA) var et = new Array(); // numbers to characters table var n2c = new Array(); for( var i=0; i < 256; ++i ){ // build a character from octal code var d1 = Math.floor(i/64); var d2 = Math.floor((i%64)/8); var d3 = i%8; var c = eval("\"\\" + d1.toString(10) + d2.toString(10) + d3.toString(10) + "\""); // modify character-code conversion tables n2c[i] = c; // modify encoding table if( i < 32 && i != 9 && i != 10 && i != 13 ){ // control characters that are not tabs, newlines, and carriage returns // create a two-character hex code representation var hex = i.toString(16); if( hex.length == 1 ) hex = "0" + hex; et[n2c[i]] = "<char code='" + hex + "'/>"; } else if( i < 128 ){ // low characters that are not special control characters et[n2c[i]] = n2c[i]; } else { // high characters et[n2c[i]] = "&#x" + i.toString(16) + ";"; } } // special escapes for CDATA encoding et["<"] = "<"; et[">"] = ">"; et["&"] = "&"; this.table = et; } _encoding = new _wddx_Encoding(); /****************************************************************************** qForm Methods ******************************************************************************/ function _a_serialize(exclude){ // if you need to reset the default values of the fields var lstExclude = (arguments.length > 0) ? "," + _removeSpaces(arguments[0]) + "," : ""; struct = new Object(); stcAllFields = qFormAPI.getFields(); // loop through form elements for( key in stcAllFields ){ if( lstExclude.indexOf("," + key + ",") == -1 ) struct[key] = stcAllFields[key]; } // create & return the serialized object return __serializeStruct(struct); } _a.prototype.serialize = _a_serialize; // define qForm serialize(); prototype function _q_serialize(exclude){ // if you need to reset the default values of the fields var lstExclude = (arguments.length > 0) ? "," + _removeSpaces(arguments[0]) + "," : ""; struct = new Object(); // loop through form elements for( var j=0; j < this._fields.length; j++ ){ if( lstExclude.indexOf("," + this._fields[j] + ",") == -1 ) struct[this._fields[j]] = this[this._fields[j]].getValue(); } // create & return the serialized object return __serializeStruct(struct); } qForm.prototype.serialize = _q_serialize;
/******************************************************************************
qForm JSAPI: WDDX Mod Library
Author: Dan G. Switzer, II
Build: 101
******************************************************************************/
qForm JSAPI: WDDX Mod Library
Author: Dan G. Switzer, II
Build: 101
******************************************************************************/
Тестировалось на: IE 6.0 SP2, Mozilla FF 1.5, Opera 8.5
