Skip to content

Commit

Permalink
validator for the number field
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkum committed Jan 6, 2015
1 parent 0953632 commit 4560d9c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -716,13 +716,15 @@
label="CONFIG_SESSION_SETTINGS_LABEL">
<field
name="lifetime"
type="text"
type="number"
default="15"
label="COM_CONFIG_FIELD_SESSION_TIME_LABEL"
description="COM_CONFIG_FIELD_SESSION_TIME_DESC"
required="true"
filter="integer"
size="6" />
size="6"
class="inputbox validate-number"
min="5" />

<field
name="session_handler"
Expand Down
3 changes: 3 additions & 0 deletions administrator/components/com_config/view/application/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function render()
return false;
}

JHtml::_('behavior.formvalidation');
JHtml::script('media/com_config/js/validate-number.js');

// Bind data
if ($form && $data)
{
Expand Down
21 changes: 21 additions & 0 deletions media/com_config/js/validate-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
;(function($){
$(function(){

document.formvalidator.setHandler('number', function(value, element){
var min = parseInt(element.prop('min')),
max = parseInt(element.prop('max'));

if(!isNaN(min) && min > value)
{
return false;
}

if(!isNaN(max) && max < value)
{
return false;
}

return true;
});
});
})(jQuery);

0 comments on commit 4560d9c

Please sign in to comment.