⚠ 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

some text before or after <input ...>



pvalen
  • profile picture
  • Member

Posted 14 June 2013 - 13:01 PM

I made the function to enter text information to the item on the form. Using callback_ (callback_edit_field,

callback_add_field) is not applicable.

I made functions for add text before, after input field and description for field.

 

to file application/libraries/grocery_crud.php

 

to class grocery_CRUD_Field_Types

- to function get_field_types() (about 55 line)
after

$field_info->display_as = ....

add text
 

$field_info->extra_output_before 
	=  isset($this->extra_output_before[$field_info->name]) ?       
		$this->extra_output_before[$field_info->name] : null;
$field_info->extra_output_after 
	=  isset($this->extra_output_after[$field_info->name]) ?
		this->extra_output_after[$field_info->name] : null;
$field_info->extra_output_description 
	=  isset($this->extra_output_description[$field_info->name]) ?      
		$this->extra_output_description[$field_info->name] : null;

to class grocery_CRUD extends grocery_CRUD_States

- to the description of the variables (about 3050 line)
after
 

protected $primary_keys = array();

add text

protected $extra_output_before = array();
protected $extra_output_after = array();
protected $extra_output_description = array();

- between functions (about 3450 line)
after
 

function display_as($field_name, $display_as = null)

add text

 

 /**
  *
  * The text before input the field
  * @param $field_name
  * @param $extra_output_before
  * @return void
  */
 public function extra_output_before($field_name, $extra_output_before = null)
 {
  if(is_array($field_name))
  {
   foreach($field_name as $field => $extra_output_before)
   {
    $this->extra_output_before[$field] = $extra_output_before; 
   }
  }
  elseif($extra_output_before !== null)
  {
   $this->extra_output_before[$field_name] = $extra_output_before;
  }
  return $this;
 }//extra_output_before
 
 /**
  *
  * The text after input the field
  * @param $field_name
  * @param $extra_output_after
  * @return void
  */
 public function extra_output_after($field_name, $extra_output_after = null)
 {
  if(is_array($field_name))
  {
   foreach($field_name as $field => $extra_output_after)
   {
    $this->extra_output_after[$field] = $extra_output_after; 
   }
  }
  elseif($extra_output_after !== null)
  {
   $this->extra_output_after[$field_name] = $extra_output_after;
  }
  return $this;
 }// extra_output_after
 
 /**
  *
  * The text after input the field like description
  * @param $field_name
  * @param $extra_output_description
  * @return void
  */
 public function extra_output_description($field_name, $extra_output_description = null)
 {
  if(is_array($field_name))
  {
   foreach($field_name as $field => $extra_output_description)
   {
    $this->extra_output_description[$field] = $extra_output_description; 
   }
  }
  elseif($extra_output_description !== null)
  {
   $this->extra_output_description[$field_name] = $extra_output_description;
  }
  return $this;
 }// extra_output_description

 

to file assets/grocery_crud/themes/flexigrid/add.php
and to file assets/grocery_crud/themes/flexigrid/views/edit.php

after (okolo 30)
 

<div class='form-input-box' id="<?php echo $field->field_name;?>_input_box">

rewrite
 

<?php echo $input_fields[$field->field_name]->input?>

on
 

<?php
echo (isset($input_fields[$field->field_name]->extra_output_before))?
      '<span class="extra_output_before">'.$input_fields[$field->field_name]->extra_output_before.'</span>' : '';
echo $input_fields[$field->field_name]->input;
echo (isset($input_fields[$field->field_name]->extra_output_after))?
      '<span class="extra_output_after">'.$input_fields[$field->field_name]->extra_output_after.'</span>' : '';
echo (isset($input_fields[$field->field_name]->extra_output_description))? 
      '<br/><small class="extra_output_description">'.$input_fields[$field->field_name]->extra_output_description.'</small>' : '';
?> 

   
it is still to be added

to file assets/grocery_crud/themes/flexigrid/css/flexigrid.css

add text
 

.extra_output_before {}
.extra_output_after {}
.extra_output_description {
display: block;
background-color: #ECECEC;
padding: 5px;
}

and set the style of drawing text

the same in files assets/grocery_crud/themes/datatables/... to

 

 

Using this functions

$this->grocery_crud
        ->extra_output_before('name', 'TEST text before');
$this->grocery_crud        
        ->extra_output_after('name', 'TEST text after');
$this->grocery_crud        
         ->extra_output_description('name', 'TEST text description');

or

$this->grocery_crud        
         ->extra_output_description('name', 'TEST text description for name')        
         ->extra_output_description('home', 'TEST text description for home');

or

$this->grocery_crud        
          ->extra_output_before('name', 'TEST text before')        
          ->extra_output_after('name', 'TEST text after')        
          ->extra_output_description('name', 'TEST text description');

davidoster
  • profile picture
  • Member

Posted 15 June 2013 - 07:51 AM

[member=pvalen], thank you for this.

I will try to check your code and come back to you.

 

A quick question though, instead of changing the core code of the library could you use this approach?


pvalen
  • profile picture
  • Member

Posted 17 June 2013 - 08:07 AM

I believe that the code provided should be included in the new version of GC and no extension. Use of callback_ (callback_edit_field, callback_add_field) to supplement the text is needlessly complicated and can not be used for entries such as date, file, etc.

 

But if you do not insert this code into a new version, so it will try to send Zalo (greysama86@gmail.com)


davidoster
  • profile picture
  • Member

Posted 17 June 2013 - 09:39 AM

The proper way to ask for code inclusion is by making a fork of GC under github, make there changes and lastly ask for a pull.

Go here.

 

I am trying to understand what you mean by saying this:

"But if you do not insert this code into a new version, so it will try to send Zalo (greysama86@gmail.com)".

 

Can you please explain more what you mean? And what [member=zalo] has to do with all this?


pvalen
  • profile picture
  • Member

Posted 18 June 2013 - 08:03 AM

On this page I have written
https://github.com/scoumbourdis/grocery-crud/issues/190

 

Zalo created the extension, which you wrote to me, so I wrote,that I send him this my proposal, if you do not insert this code into a new version.


davidoster
  • profile picture
  • Member

Posted 20 June 2013 - 14:26 PM

OK! Just to let you know, Zalo's extension is used as a base and each one of uses it to our liking.

Zalo doesn't have to include something that myself, I or even John builds!

 

Suggestion: Make a fork of Zalo's extension and build on this fork you suggestions and share the repository with the community!


DrPaul
  • profile picture
  • Member

Posted 27 May 2014 - 20:22 PM

Interesting idea.

 

Even more so if you tweak it a little further to "inject" styling information etc into the actual input tag! (Details on request :-)


DrPaul
  • profile picture
  • Member

Posted 28 June 2014 - 14:47 PM

Found a use for this in one of my projects, so I implemented your mods - works well.

 

However, I found that for my particular application the extra output was only needed when adding a new item, not when making an edit.

 

So I "doubled up" your core code, using _add and _edit suffixes and then amending add.php and edit.php views accordingly - this way you can define extra output for add or edit independently.