⚠ In case you've missed it, we have migrated 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 is an archived forum. ⚠

  •     

profile picture

facilty for default action to occurr on callback_add_field/callback_edit_field ..etc



ezgoen
  • profile picture
  • Member

Posted 29 March 2013 - 03:40 AM

 

Hi Folks,

 

Thanks again for GroceryCrud

 

could I suggest this simple modification.

 

allow the default field drawing to occur if the user returns false (or possibly non string??)

from the callback.

 

Here's my example mod for just one function in 

/libraries/grocery_crud.php

 

protected function get_add_input_fields($field_values = null)
	{
		$fields = $this->get_add_fields();
		$types 	= $this->get_field_types();
		
		$input_fields = array();
		
		foreach($fields as $field_num => $field)
		{	
			$field_info = $types[$field->field_name];
			
			$field_value = !empty($field_values) && isset($field_values->{$field->field_name}) ? $field_values->{$field->field_name} : null;
			
			if(!isset($this->callback_add_field[$field->field_name]))
			{
				$field_input = $this->get_field_input($field_info, $field_value);
			}
			else
			{
				$field_input = $field_info;
				$field_input->input = call_user_func($this->callback_add_field[$field->field_name], $field_value, null, $field_info);
				//make our little change
				//allow default field rendering behaviour if user returns false
				//in the callback
				if ($field_input->input === False) {
					$field_input = $this->get_field_input($field_info, $field_value);
				}
			}
			
			switch ($field_info->crud_type) {
				case 'invisible':
					unset($this->add_fields[$field_num]);
					unset($fields[$field_num]);
					continue;
				break;
				case 'hidden':
					$this->add_hidden_fields[] = $field_input;
					unset($this->add_fields[$field_num]);
					unset($fields[$field_num]);
					continue;
				break;
			}			
			
			$input_fields[$field->field_name] = $field_input; 
		}
		
		return $input_fields;
	}

 

The other field callback functions could work similarly

 

what do you think??

 

cheers,,

 

EZ