Show/Hide Fields per Actrive Record Value
- Single Page
Posted 20 September 2012 - 20:02 PM
How can I accomplish this?
I had hoped to be able to build the list of my "fields" or "editfields" via an array, but there does not seem to be a way to get the VALUE of the Current/Active record so that the correct fields are displayed:
Can I change the line of code below somehow to get the "Active Record" Field Values:
$AnalyType = $crud->$fields->AnalysisType; <==DOES NOT WORK...
Below is the code I am working on:
$crudstate = $crud->getState(); #Get Crud State: Add, Edit, Etc...
#
$crudfields = array('AnalysisType', 'Cust_id', 'LeaseUnit', 'WellNo', 'Field', 'County', 'District', 'State',
'SampleLoc', 'SampleDate', 'SubmittedBy',
'AnalystId', 'SalesmanId','SalesmanId2', 'LabHours', 'LabDateIn', 'LabDateOut',
'Observations', 'LabNotes', 'Status');
#**
#* Add Result Fields per Analysis Test Type - EDIT MODE
#**
if($crudstate == 'edit') {
$AnalyType = $crud->$fields->AnalysisType;
switch ($AnalyType) {
case 'Suspended Oil Analysis':
$crudfields[] = 'AOil'; #Add Results Field for Edit/Update
break;
case 'Iron and Manganese Analysis':
$crudfields[] = 'AIron'; #Add Results Field for Edit/Update
$crudfields[] = 'AManganese'; #Add Results Field for Edit/Update
break;
}
}
$crud->fields($crudfields);
Posted 20 September 2012 - 20:47 PM
http://www.grocerycrud.com/documentation/options_functions/change_field_type
or use this:
http://www.grocerycrud.com/documentation/options_functions/callback_field
Inside callback_field function you can call model functions.
Posted 20 September 2012 - 21:38 PM
Thanks, BUT neither of those work for me because:
The change_field_type technique might work IF i can figure out how to change field settings based on the VALUE of other fields in the Current Record.
That is basically what I am trying to do in my code (above) is to control what fields show based on a VALUE in the CURRENT RECORD.
I still don't see how make it work...
The callback_field technique allows me to get rid of the "input" tag but NOT the "label' for the field so the row for the field I am trying not to show still shows up.
I also don't have a handy way to test the OTHER FIELD values (AnalysisType) to control the hiding since I only get the Primary Key of the record passed in so I would have to go query the record myself and then that would only contain the values of the OLD (pre-update) record NOT the record's field values on the screen...
Still stumped...
Posted 21 September 2012 - 11:20 AM
I got this working by using a CI generic_model to get the current records value during the "edit" state and then using $crud->change_field_type to "hide" the fields I did not want to see.
It was easy...
Thanks again.