Add frontside support for locale dependent number validation (#788)

This commit is contained in:
jekkos
2016-08-09 18:20:52 +02:00
parent 597a5caee5
commit 8b08bf5daa
6 changed files with 33 additions and 21 deletions

View File

@@ -99,11 +99,6 @@ class Receivings extends Secure_Controller
$this->_reload($data);
}
function numeric($str)
{
return parse_decimals($str, 3);
}
public function edit_item($item_id)
{
$data = array();

View File

@@ -285,11 +285,6 @@ class Sales extends Secure_Controller
$this->_reload($data);
}
function numeric($str)
{
return parse_decimals($str, 3);
}
public function edit_item($item_id)
{
$data = array();

View File

@@ -50,7 +50,21 @@ class Secure_Controller extends CI_Controller
return $this->security->xss_clean($str, $is_image);
}
}
function numeric($str)
{
return parse_decimals($str);
}
public function check_numeric()
{
$result = TRUE;
foreach($this->input->get() as $str) {
$result = parse_decimals($str);
}
echo $result !== FALSE ? 'true' : 'false';
}
// this is the basic set of methods most OSPOS Controllers will implement
public function index() { return FALSE; }
public function search() { return FALSE; }

View File

@@ -82,6 +82,10 @@ function parse_decimals($number)
$config = get_instance()->config;
$fmt = new \NumberFormatter( $config->item('number_locale'), \NumberFormatter::DECIMAL );
if (empty($config->item('thousands_separator')))
{
$fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
}
return $fmt->parse($number);
}

View File

@@ -264,18 +264,22 @@ $(document).ready(function()
default_tax_1_rate:
{
required: true,
number: true
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
default_tax_1_name: "required",
default_tax2_rate:
{
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
lines_per_page:
{
required: true,
number: true
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
default_sales_discount:
{
required: true,
number: true
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
}
},

View File

@@ -376,13 +376,13 @@
},
cost_price:
{
required:true,
number:true
required: true,
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
unit_price:
{
required:true,
number:true
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
<?php
foreach($stock_locations as $key=>$location_detail)
@@ -391,7 +391,7 @@
<?php echo 'quantity_' . $key ?>:
{
required:true,
number:true
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
<?php
}
@@ -399,17 +399,17 @@
receiving_quantity:
{
required:true,
number:true
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
reorder_level:
{
required:true,
number:true
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
},
tax_percent:
{
required:true,
number:true
remote: "<?php echo site_url($controller_name . '/check_numeric')?>"
}
},