Jump to content


Dropdown field type problem

dropdown input field

  • Please log in to reply
2 replies to this topic

#1 RMaynard

RMaynard

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 08 November 2017 - 07:02 PM

This is my first time using this platform and have a problem with the dropdown input type. If I use the following code:

 
$crud->field_type('agency','dropdown',
array('1' => 'corps', '2' => 'fs','3' => 'katy','4' => 'mocons','5' => 'mopark','6' => 'nps','7' => 'ot'));
 
It works pretty much as expected when entering a new record, however, when editing a record the 'agency' field doesn't show the value already in the record, just the dropdown. Since this is not a requird field, if you don't know what is in the field and don't choose one, updating the record stores a null in the field and the information is lost.
 
Is there a way to default the input field to the value in the record and show the contents of the 'agency' field when the edit page loads?  Does this require a callback function like callback_edit_field(), and if so how do I implement it?
 
Thanks for your help.


#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 09 November 2017 - 04:17 AM

Well my friend,

 

very 1st thing - can you update me on 1 thing - is there  a field (agency) stored in the table? if so, can you cross check if the relevant value is going into the table during insert?

 

1 thing - if you always have this static values - then i will rather recommend u change the field to enum. If you anyways going to store just IDs - then u better have another table to which u join in with relation.



#3 RMaynard

RMaynard

    Newbie

  • Members
  • Pip
  • 7 posts

Posted 09 November 2017 - 12:21 PM

Amit, thanks for your help. I do have a field 'agency' and I will only have a small number of possible values stored there, so thought it overkill to have a table with just 4 or 5 values. I think I may have this working. The field 'agency' is a type varchar(20) and I think my original code was storing a numeric value there. I chanced it to the following and it seems to be working now.

 
$crud->field_type('agency','dropdown',
array('corps' => 'Corps of Eng', 'fs' => 'Forrest Service','katy' => 'Katy Trail','mocons' => 'MO Conservation','mopark' => 'MO Parks','nps' => 'National Parks','ot' => 'Ozark Trail'));

 

I know just enough to be dangerous :)







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users