model_params usage

edited August 2014 in Modules
In the definitions for form builder inputs, there is a parameter I've not used yet "model_params". Is this the 3rd argument to options_list(), ie the "where"? I'm not sure how it should be used, the docs don't seem to have an example.

Comments

  • edited 3:46PM
    Its an array of arguments to pass to the method specified which by default is the 'options_list' method. Form_builder uses call_user_func_array so may need to do something like the following:
    'model_params' => array('id', 'name', array('category_id' => 2))...
    Note that the third value in the model_params array is the where condition.
  • edited 3:46PM
    The value of the where must be static I guess?
  • edited 3:46PM
    Correct. Are you looking for a field type that will dynamically change the options based on another selection or something like that (a dependent field type)?
  • edited August 2014
    My scenario was an edit page on which this form would appear, so grabbing the id from the url could filter the checkboxes generated by the field. I think this is possible, I threw in "current_url()" as a value, just to see what would happen, and sure enough, the SQL tried to compare a field to the current url...

    .. and further to that I've been able to retrieve the id with a helper function, which assigns a value at runtime for the field configuration. Of course, this does limit the form to being used at one url only, but that's fine.
Sign In or Register to comment.