summaryrefslogtreecommitdiffhomepage
path: root/libs
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-10-21 20:50:18 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-10-21 20:50:18 +0000
commit98b4da49b0f7af5bc52e8a7da8eaa759e5fda0e2 (patch)
tree5083855a7c363aeadb39810f04d66919dc1ccbf4 /libs
parent0d3fc50989009ca85c0d39bb043bf1317fa5cf60 (diff)
libs/web: fix ip6addr js validation, fixes for live validation
Diffstat (limited to 'libs')
-rw-r--r--libs/web/htdocs/luci-static/resources/cbi.js43
1 files changed, 19 insertions, 24 deletions
diff --git a/libs/web/htdocs/luci-static/resources/cbi.js b/libs/web/htdocs/luci-static/resources/cbi.js
index 7c5dd4ef46..74a2576736 100644
--- a/libs/web/htdocs/luci-static/resources/cbi.js
+++ b/libs/web/htdocs/luci-static/resources/cbi.js
@@ -70,34 +70,25 @@ var cbi_validators = {
addr = addr.substr(0, off) + ':0:0';
}
- if( addr.indexOf('::') < 0 )
+ if( addr.indexOf('::') >= 0 )
{
- return (addr.match(/^(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/) != null);
- }
+ var colons = 0;
+ var fill = '0';
- var fields = 0;
+ for( var i = 0; i < addr.length; i++ )
+ if( addr.charAt(i) == ':' )
+ colons++;
- for( var i = 0, last = 0, comp = false; i <= addr.length; i++ )
- {
- if( (addr.charAt(i) == ':') || (i == addr.length) )
- {
- if( (i == last) && !comp )
- {
- comp = true;
- }
- else
- {
- var f = addr.substring(last, i);
- if( !(f && f.match(/^[a-fA-F0-9]{1,4}$/)) )
- return false;
- }
-
- fields++;
- last = i + 1;
- }
+ if( colons > 7 )
+ return false;
+
+ for( var i = 0; i < (7 - colons); i++ )
+ fill += ':0';
+
+ addr = addr.replace(/::/, ':' + fill + ':');
}
- return (fields == 8);
+ return (addr.match(/^(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$/) != null);
}
}
@@ -462,6 +453,10 @@ function cbi_t_update() {
function cbi_validate_form(form, errmsg)
{
+ /* if triggered by a section removal or addition, don't validate */
+ if( form.cbi_state == 'add-section' || form.cbi_state == 'del-section' )
+ return true;
+
if( form.cbi_validators )
{
for( var i = 0; i < form.cbi_validators.length; i++ )
@@ -494,7 +489,7 @@ function cbi_validate_field(cbid, optional, type)
if( field && vldcb )
{
- var validator = function(reset)
+ var validator = function()
{
// is not detached
if( field.form )