Jump to content


input type=number

form input numeric

  • Please log in to reply
1 reply to this topic

#1 judge

judge

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 23 March 2016 - 07:10 PM

Hi,

 

I would like to suggest the the input type for numeric values be changed to number from text. It should be backwards compatible with all browsers and allows adaptive keyboards to be displayed on mobile devices.

 

In the same vein, it would be nice if the framework recognized other numeric types as numeric, e.g. float, double, decimal...



#2 judge

judge

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 12 April 2016 - 10:26 AM

Create a file Grocery_CRUD_Extended.php in application/libraries

<?php
/**
 * Display numeric input fields as numbers
 */
class Grocery_CRUD_Extended extends Grocery_CRUD {
	protected function get_integer_input($field_info, $value) {
		$this->set_js_lib ( $this->default_javascript_path . '/jquery_plugins/jquery.numeric.min.js' );
		$this->set_js_config ( $this->default_javascript_path . '/jquery_plugins/config/jquery.numeric.config.js' );
		$extra_attributes = '';
		if (! empty ( $field_info->db_max_length ))
			$extra_attributes .= "maxlength='{$field_info->db_max_length}'";
		$input = "<input id='field-{$field_info->name}' name='{$field_info->name}' type='number' value='$value' class='numeric form-control' $extra_attributes />";
		return $input;
	}
	protected function get_string_input($field_info, $value) {
		$value = ! is_string ( $value ) ? '' : str_replace ( '"', "&quot;", $value );
		$input_type = 'text';
		
		$extra_attributes = '';
		
		if (in_array ( $field_info->type, array (
				'decimal',
				'float',
				'real',
				'double' 
		) )) {
			$input_type = 'number';
			$extra_attributes = ' step="any" ';
		}
		
		if (! empty ( $field_info->db_max_length )) {
			
			if (in_array ( $field_info->type, array (
					"decimal",
					"float" 
			) )) {
				$decimal_lentgh = explode ( ",", $field_info->db_max_length );
				$decimal_lentgh = (( int ) $decimal_lentgh [0]) + 1;
				
				$extra_attributes .= "maxlength='" . $decimal_lentgh . "'";
			} else {
				$extra_attributes .= "maxlength='{$field_info->db_max_length}'";
			}
		}
		$input = "<input id='field-{$field_info->name}' class='form-control' name='{$field_info->name}' type='$input_type' value=\"$value\" $extra_attributes />";
		return $input;
	}
}

Use as follows:

/*
 * In constructor
 */

$this->load->library ( 'grocery_CRUD' );
$this->load->library ( 'Grocery_CRUD_Extended' );

/*
 * In methods
 */

$crud = new Grocery_CRUD_Extended ();






Also tagged with one or more of these keywords: form, input, numeric

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users