Custom Field Rendering

25.01.2017 | Laravelpanel

1. DataField Klasse kopieren

 z.B nach: app/Fields/Text.php

richtigen Namespace vergeben und Änderungen einbauen:

<?php 

namespace blog\Fields;

use Collective\Html\FormFacade as Form;
use Zofe\Rapyd\Rapyd;
use Zofe\Rapyd\DataForm\Field\Field;

class Text extends Field
{
  public $type = "text";

  public function build()
  {
    $output = "";

    if (parent::build() === false) return;

    switch ($this->status) {
      case "disabled":
      case "show":

        if ($this->type =='hidden' || $this->value == "") {
          $output = "";
        } elseif ( (!isset($this->value)) ) {
          $output = $this->layout['null_label'];
        } else {
          $output = nl2br(htmlspecialchars($this->value));
        }
        $output = "<div class='help-block'>".$output."&nbsp;</div>";
        break;

      case "create":
      case "modify":
        $output = Form::text($this->name, $this->value, array_merge(array('onKeyUp'=>'updateElement(this, \'slug\')'),$this->attributes));
        break;

      case "hidden":
        $output = Form::hidden($this->name, $this->value);
        break;

      default:;
    }
    $this->output = "\n".$output."\n". $this->extra_output."\n";
  }

}

 

2. Datenfeld einbauen

   $this->edit->add('title', 'Title','blog\Fields\Text')->rule('required');

 

In diesem Fall noch ein Javascipt ins master.blade.php:

 <script>
        function updateElement(from, to)
        {
            var val = from.value.toLowerCase().replace(/\ /gi,'-').replace(/[?!.,\(\)#\+]/gi, '');
            val = val.replace(/ä/g, 'ae');
            val = val.replace(/ö/g, 'oe');
            val = val.replace(/ü/g, 'ue');
            val = val.replace(/ß/g, 'ss');
            document.getElementById(to).value = val;
        }
    </script>

Analyse

Entwurf

Development

Launch