Jump to content


How to add some custom anotations in a Form

grocerycrud new register custom

  • Please log in to reply
2 replies to this topic

#1 Pedro Bernal

Pedro Bernal

    Member

  • Members
  • PipPip
  • 12 posts

Posted 10 February 2015 - 06:29 AM

Hi, I want to know if is there a way to add some aclarations or anotations for fields into a groceryCrud form, in order to clarify what information should the user enter in some tricky fields.

 

Thanks.



#2 Amit Shah

Amit Shah

    grocery CRUD Master

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

Posted 11 February 2015 - 04:18 PM

Hi there

 

even i wanted the same solution so had buit 1 for myself.. you surely can change it according to things that suite u

class Grocery_CRUD extends grocery_CRUD_States
{
...
...
	protected $field_tips							= array();				//Add a variable to collect all the field tips
	
...
...
	/**
	 * //Add up a function additional to set field tips 
	 * Sets tips to the given field that will be displayed to the right of the field
	 * @param string $field
	 * @param string $mask
	 */
	public function field_tip($field , $tip)
	{
		$this->field_tips[$field] = $tip;
		return $this;
	}
	
	
...
...
...
//Then some place below in showAddForm ... 
	protected function showAddForm()
	{	
	....
	...
	$data->tips				= $this->field_tips;
	...
	...

//Then some place below in showEditForm ... 
	protected function showEditForm($state_info)
	{
	....
	...
	$data->tips				= $this->field_tips;
	...
	...
	

//////////////////now in themes .. add.php / edit.php
	<?php echo $input_fields[$field->field_name]->input?>
	///After the line above.. just add the following ..and thats it
	<?php if(array_key_exists($field->field_name, $tips)) { ?>
	&nbsp;<span class="tips"><?php echo $tips[$field->field_name]?></span>
	<?php } ?>
	

now the set a tip in the controller for any field

$crud->field_tip('icon', 'Max Allowed Size - 1 MB, Recomended Dimension - 100x100');

This is a good example as how to add your own functionality to grocery crud (mind it.. this is true only when u want to add the functionality @global level)

 

Happy GCing :)



#3 pvalen

pvalen

    Member

  • Members
  • PipPip
  • 15 posts

Posted 11 March 2015 - 04:07 PM

I wrote about it too

http://www.grocerycr...or-after-input/







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users