⚠ In case you've missed it we are migrating to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This forum is read-only and soon will be archived. ⚠


Arjunraj

Member Since 28 Aug 2017
Offline Last Active Nov 20 2017 01:28 PM
-----

Topics I've Started

Problem with editing radio button

28 August 2017 - 03:15 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.
            $crud->callback_add_field('government', function() {
       return '<input type="radio" name="government" value="Y" /> Yes  &nbsp;     // "Y" and  "N" are the enum values that I have given in database.
                 <input type="radio" name="government" value="N" /> No';
        });
 
       // 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.
            if($value == 'Y') {
        return '<input type="radio" name="government" value=" '.$value.' " checked="checked" /> Yes &nbsp;
               <input type="radio"  name="government" value="N" /> No '; } 
 
      else  return '<input type="radio" name="government" value="Y" /> Yes &nbsp;
        <input type="radio" name="government" value=" '.$value.' " checked="checked" /> No'; 
 
    }
The above code works for insertion and if we change that radio button from 'y' to 'n' or 'n' to 'y' in an edit functionality.
 
But The only problem is , when I press edit and if I did not change anything and press update changes , then there will be nothing stored in government column(i.e Y or N), can anyone help me with this..