scoumbourdis / grocery-crud

Grocery CRUD is a PHP Codeigniter Framework library that creates a full functional CRUD system without the requirement of extra customisation to the JavaScripts or the CSS to do it so.
http://www.grocerycrud.com
GNU General Public License v3.0
1.01k stars 472 forks source link

some text before or after <input ...> #190

Open pvalen opened 11 years ago

pvalen commented 11 years ago

Hi,

please I would like you to do a new function, so I could add some text before or after <input ...> etc. grocerycrud_input_text

Using the callbacks is difficult and can not be used for inserting the date, file, etc.

Thanks

Petr

pvalen commented 11 years ago

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. You can add it to the new version.

to file _application/libraries/grocerycrud.php

to class _grocery_CRUD_FieldTypes

$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_CRUDStates

protected $primary_keys = array();

add text

protected $extra_output_before = array();
protected $extra_output_after = array();
protected $extra_output_description = array();
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/grocerycrud/themes/flexigrid/add.php and to file _assets/grocerycrud/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/grocerycrud/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/grocerycrud/themes/datatables/... to