Example #1
0
 public static function toFormField($table = '', $column = '')
 {
     //Get the column's configuration
     $column_config = Config::get('scaffenger.tables.' . $table . '.columns.' . $column);
     $field_attributes = isset($column_config['attributes']['inForm']) ? $column_config['attributes']['inForm'] : [];
     $formHtml = new FormHtml($column, $column_config, $field_attributes);
     switch ($column_config['type']) {
         case 'fk':
             switch ($column_config['relationship']['type']) {
                 case 'belongsTo':
                     $column_html = $formHtml->belongsTo();
                     break;
                 case 'belongsToMany':
                     $column_html = $formHtml->belongsToMany(Config::get('scaffenger.tables.' . $table . '.model'));
                     break;
             }
             break;
         case 'image':
             $column_html = $formHtml->image(Config::get('scaffenger.tables.' . $table . '.model'), \Form::getValueAttribute('id'));
             break;
         case 'slug':
             $column_html = $formHtml->slug();
             break;
         case 'textarea':
             $column_html = $formHtml->textarea();
             break;
         case 'password':
             $column_html = $formHtml->password();
             break;
         case 'select':
             $column_html = $formHtml->select();
             break;
         case 'order':
             $column_html = $formHtml->order(Config::get('scaffenger.tables.' . $table . '.model'));
             break;
         case 'bool':
             $column_html = $formHtml->bool();
             break;
         case 'email':
             $column_html = $formHtml->email();
             break;
         case 'url':
             $column_html = $formHtml->url();
             break;
         case 'address':
             $column_html = $formHtml->address();
             break;
         case 'hidden':
             $column_html = $formHtml->hidden();
             break;
         default:
             //text, image,
             $column_html = $formHtml->text();
             break;
     }
     return $column_html;
 }
Example #2
0
 public static function select($name, $data = array(), $options = array())
 {
     $value = Form::getValueAttribute($name);
     //Si el modelo ya tiene este atributo se le da importancia.
     if ($value != null) {
         $options['value'] = $value;
     }
     $full_name = self::getName($name);
     $id = self::getClass($name);
     if (isset($options['class']) && $options['class'] != '') {
         //Si ya tiene clase se añade la generada a la lista de clases
         $options['class'] = $options['class'] . ' ' . $id;
     } else {
         //Si no se usa esta clase como única
         $options['class'] = $id;
     }
     if (!self::$is_array && !isset($options['id'])) {
         //Si el modelo es unico y no existe id.
         $options['id'] = $id;
     }
     return Form::select($full_name, $data, null, $options);
 }
Example #3
0
    if ($value == null) {
        // Get old form input type field (Does not work on textarea, select)
        $value = Form::getValueAttribute($name);
    }
    return "<div class='form-group " . errorClass($name) . "'>\n            <label class='control-label' for='{$name}'>{$label}</label>" . Form::text($name, $value, ['class' => 'form-control', 'placeholder' => $placeholder]) . errorMessage($name) . "</div>";
});
Form::macro('passwordField', function ($name, $label, $placeholder) {
    return "<div class='form-group " . errorClass($name) . "'>\n            <label class='control-label' for='{$name}'>{$label}</label>\n            <input type='password' name='{$name}' class='form-control' id='{$name}' placeholder='{$placeholder}'>" . errorMessage($name) . "</div>";
});
Form::macro('emailField', function ($name, $label, $placeholder = '') {
    $value = Form::getValueAttribute($name);
    // Get old form input type field (Does not work on textarea, select)
    return "<div class='form-group " . errorClass($name) . "'>\n            <label class='control-label' for='{$name}'>{$label}</label>\n            <input type='email' name='{$name}' class='form-control' id='{$name}' value='{$value}' placeholder='{$placeholder}'>" . errorMessage($name) . "</div>";
});
Form::macro('textareaField', function ($name, $label, $placeholder) {
    $value = Form::getValueAttribute($name);
    $element = Form::textarea($name, $value, ['placeholder' => $placeholder, 'class' => 'form-control', 'id' => $name]);
    return "<div class='form-group " . errorClass($name) . "'>\n            <label class='control-label' for='{$name}'>{$label}</label>\n            {$element}" . errorMessage($name) . "</div>";
});
Form::macro('selectField', function ($name, $options, $value, $label) {
    $element = Form::select($name, $options, $value, ['class' => 'form-control']);
    return "<div class='form-group " . errorClass($name) . "'>\n            <label class='control-label' for='{$name}'>{$label}</label>\n            {$element}" . errorMessage($name) . "</div>";
});
Form::macro('multiSelectField', function ($name, $options, $value = null, $label) {
    $element = Form::select($name, $options, $value, ['class' => 'form-control multiselect', 'multiple']);
    return "<div class='form-group " . errorClass($name) . "'>\n            <label class='control-label' for='{$name}'>{$label}</label>\n            {$element}" . errorMessage($name) . "</div>";
});
Form::macro('selectTag', function ($name, $id, $label) {
    return "<div class='form-group " . errorClass($name) . "'>\n            <label class='control-label' for='{$name}'>{$label}</label>\n            <input id='{$id}' class='form-control' name='{$name}'/>" . errorMessage($name) . "</div>";
});
Form::macro('fileField', function ($name, $label) {
<?php

/**
 * Created by PhpStorm.
 * User: bazi
 * Date: 05-Aug-15
 * Time: 8:50 AM
 */
Form::macro('category', function ($name, $cattree = array(), $selected = null, $options = array()) {
    $selected = Form::getValueAttribute($name, $selected);
    $options['id'] = $this->getIdAttribute($name, $options);
    if (!isset($options['name'])) {
        $options['name'] = $name;
    }
    $html = [];
    foreach ($cattree as $catkey => $cat) {
        //        $html .= '<optgroup label="' . $catkey . '"></optgroup>';
        foreach ($cat as $subcatkey => $subcat) {
            //            $html .= '<optgroup label="' . $subcatkey . '"></optgroup>';
            $html[] = Form::getSelectOption($subcat, $subcatkey, $selected);
            //            foreach($subcat as $postcatkey => $postcat) {
            //                $html .= '<option value="' . $postcatkey . '">' . $postcat . '</option>';
            //                $html[] = Form::getSelectOption($postcat, $postcatkey, $selected);
            //            }
        }
    }
    //    foreach ($list as $value => $display)
    //    {
    //        $html[] = $this->getSelectOption($display, $value, $selected);
    //    }
    $list = implode('', $html);
Example #5
0
function input($name, $display, $data = array())
{
    //$data['class'] = $name;
    $data['onkeyup'] = 'precio()';
    $data['size'] = '6';
    return MyForm::field($name, $display, $data);
    $value = Form::getValueAttribute($name);
    $f_name = "modulo[{$name}]";
    return '<div class="input-field">' . Form::label($f_name, $display) . Form::text($f_name, $value, $data) . '</div>';
}
        $Value = $v;
    }
    $Attributes['class'] = implode(' ', [@$Attributes['class'], 'style-check']);
    $Attributes['id'] = $Name;
    $check = Form::checkbox($Name, $Value, $Checked, $Attributes);
    $check .= "<label class='style-check-label' for='{$Name}'></label>";
    $check .= "<label for='{$Name}'>{$Label}</label>";
    return $check;
});
Form::macro('infolabel', function ($Name, $Text, $Info, array $Attributes = array()) {
    $attr = AttributesToHtml($Attributes);
    return "<label for='{$Name}'{$attr}>{$Text} <span class='hint'>{$Info}</span></label>";
});
//Input type=date, auto converts data if int or DateTime
Form::macro('date', function ($Name, $Date = '', array $Attributes = array()) {
    $v = Form::getValueAttribute($Name);
    if (!empty($v)) {
        $Date = $v;
    }
    $attr = AttributesToHtml($Attributes);
    if ($Date instanceof DateTime) {
        $Date = $Date->format('o-m-d');
    } else {
        if (is_int($Date)) {
            $Date = date('o-m-d', $Date);
        } else {
            if (is_string($Date)) {
                $Date = date('o-m-d', strtotime($Date));
            }
        }
    }