How to add radiobutton/radiobutton with custom value
- Single Page
Posted 29 May 2012 - 11:21 AM
I am very much impressed with your tool.
I am yet to see some examples using radiobutton or dropdown boxes which are missing. Is there any tutorial for that?
Say for example.. I have a gender column in database table which expects values Male | Female (values are custom)
How do you implement this?
Also if I want to display it as a dropdownbox also.. Pls provide me sample codes for radiobutton and dropdown box.
Thanks,
Demis John
Posted 29 May 2012 - 12:52 PM
i dunno about radio button if it can be directly render like that of dropdown for enum data types... but you can use [b]callback_add_field[/b] function to add radio button.. i hope it may work for you
function example_callback_add_field(){
$crud = new grocery_CRUD();
$crud->set_table('offices');
$crud->set_subject('Office');
$crud->required_fields('city');
$crud->columns('city','country','gender','addressLine1','postalCode');
$crud->callback_add_field('gender',array($this,'add_field_callback_1'));
$output = $crud->render();
$this->_example_output($output);
}
function add_field_callback_1()
{
return ' <input type="radio" name="sex" value="male" /> Male
<input type="radio" name="sex" value="female" /> Female';
}
Posted 29 May 2012 - 13:03 PM
Posted 29 May 2012 - 16:34 PM
Posted 29 May 2012 - 16:40 PM
Posted 29 May 2012 - 17:28 PM
Another simple possibility for radio buttons is to use:
$crud->change_field_type('your_field','true_false');
The only problem here is you are stuck with the default button labels of "active" and "inactive" and values of 1 and 0, respectively.
Posted 28 June 2012 - 17:59 PM
Posted 18 March 2013 - 20:04 PM
You can change the values of radio buttons in the config file for your language. for english, it's here:
assets\grocery_crud\languages\english.php
Just change these 2 lines:
Posted 17 September 2013 - 11:43 AM
Hello
I have wanted to know how to make the checkbox is the value of the db. Otherwise, when the checkbox is edict are always equal to 0 even if the value is 1
Posted 28 August 2017 - 13:16 PM
Hi I am new to grocery CRUD , I surfed on internet to find the solution for this , but I found none,
Myself found one solution for radio button edit , Hope this helps
$crud->change_field_type('government','true_false');
// This part is for inserting, 'government' is the name of the field or column name in the database table.
// now This part is for update or edit
$crud->callback_edit_field('government',array($this,'radio_edit_callback'));
//Function for the callback_edit_field
public function radio_edit_callback($value) { //$value will be having the present value(Y or N) that is in the list or database.
Posted 28 August 2017 - 15:14 PM
Posted 29 August 2017 - 04:48 AM
Inspect in developer tools (Chrome / firefox) .. check the value of the field that gets submitted back. Is it the value that goes as expected or what.. if not, then u need to re-work on the form generation (Field alteration) where your value is getting passed on.
Posted 29 August 2017 - 06:57 AM
Thanks for the tip Mr. Amit shah , I found the solution to that problem, there was spaces between the double quotes (value=" '.$value.' ") that is the reason , The value was passing (one space) instead of the $value(Y or N), Now its working all good . I corrected the above code as value="'.$value.'" (There should be no space between the double quotes and single quote).
Thank you Once again.