laravel-api-generator icon indicating copy to clipboard operation
laravel-api-generator copied to clipboard

Custom Format for the fields generator

Open anheru88 opened this issue 9 years ago • 5 comments

Hi Mitul, first of all let me tell you thanks, for this package, is so helpfull, the second i try to customice the $FIELD_INPUT$ generators but i can't becouse no exist a file or template, can let me change this.

I try to change in your FormFieldsGenerator, but no is the good way, i create a Gist, i hope you can think in one solution for this.

anheru88 avatar Jun 12 '15 06:06 anheru88

I can use the DynamicVariables inside of the fields.blade.php like this.

$FIELDS$
<div class="hr-line-dashed"></div>
<!--- Submit Field --->
<div class="form-group">
    <div class="col-sm-4 col-sm-offset-2">
        <a href="{!! route('$MODEL_NAME_PLURAL_CAMEL$.index') !!}"> $MODEL_NAME_PLURAL$ </a>
        {!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
    </div>
</div>```

anheru88 avatar Jun 12 '15 06:06 anheru88

I can't find Gist.

mitulgolakiya avatar Jul 01 '15 07:07 mitulgolakiya

This is the Gist. I Modified the FormFieldsGenerator,

'col-sm-2 control-label']) !!}"; $template = str_replace('$FIELD_NAME_TITLE$', $label, $template); $template = str_replace('$FIELD_NAME$', $field['fieldName'], $template); return $template; } private static function replaceFieldVars($textField, $field) { $label = Str::title(str_replace("_", " ", $field['fieldName'])); $textField = str_replace('$FIELD_NAME$', $field['fieldName'], $textField); $textField = str_replace('$FIELD_NAME_TITLE$', $label, $textField); $textField = str_replace('$FIELD_INPUT$', $textField, $textField); return $textField; } public static function text($templateData, $field) { $textField = self::generateLabel($field); $textField .= '
'; $textField .= "\n\t{!! Form::text('\$FIELD_NAME\$', null, ['class' => 'form-control']) !!}"; $textField .= '
'; $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData); $templateData = self::replaceFieldVars($templateData, $field); return $templateData; } public static function textarea($templateData, $field) { $textareaField = self::generateLabel($field); $textareaField .= '
'; $textareaField .= "\n\t{!! Form::textarea('\$FIELD_NAME\$', null, ['class' => 'form-control']) !!}"; $textareaField .= '
'; $templateData = str_replace('$FIELD_INPUT$', $textareaField, $templateData); $templateData = self::replaceFieldVars($templateData, $field); return $templateData; } public static function password($templateData, $field) { $textField = self::generateLabel($field); $textField .= '
'; $textField .= "\n\t{!! Form::password('\$FIELD_NAME\$', ['class' => 'form-control']) !!}"; $textField .= '
'; $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData); $templateData = self::replaceFieldVars($templateData, $field); return $templateData; } public static function email($templateData, $field) { $textField = self::generateLabel($field); $textField .= '
'; $textField .= "\n\t{!! Form::email('\$FIELD_NAME\$', null, ['class' => 'form-control']) !!}"; $textField .= '
'; $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData); $templateData = self::replaceFieldVars($templateData, $field); return $templateData; } public static function file($templateData, $field) { $textField = self::generateLabel($field); $textField .= '
'; $textField .= "\n\t{!! Form::file('\$FIELD_NAME\$') !!}"; $textField .= '
'; $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData); $templateData = self::replaceFieldVars($templateData, $field); return $templateData; } public static function checkbox($templateData, $field) { $textField = "
\n"; $textField .= "\t\t"; $textField .= "\n\t
"; $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData); $templateData = self::replaceFieldVars($templateData, $field); return $templateData; } public static function radio($templateData, $field) { $textField = self::generateLabel($field); if (sizeof($field['typeOptions']) > 0) { $arr = explode(",", $field['typeOptions']); foreach ($arr as $item) { $label = Str::title(str_replace("_", " ", $item)); $textField .= "\n\t
"; $textField .= "\n\t\t"; $textField .= "\n\t
"; } } $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData); $templateData = self::replaceFieldVars($templateData, $field); return $templateData; } public static function number($templateData, $field) { $textField = self::generateLabel($field); $textField .= '
'; $textField .= "\n\t{!! Form::number('\$FIELD_NAME\$', null, ['class' => 'form-control']) !!}"; $textField .= '
'; $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData); $templateData = self::replaceFieldVars($templateData, $field); return $templateData; } public static function date($templateData, $field) { $textField = self::generateLabel($field); $textField .= '
'; $textField .= "\n\t{!! Form::date('\$FIELD_NAME\$', null, ['class' => 'form-control']) !!}"; $textField .= '
'; $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData); $templateData = self::replaceFieldVars($templateData, $field); return $templateData; } public static function select($templateData, $field) { $textField = self::generateLabel($field); $textField .= "
"; $textField .= "{!! Form::select('\$FIELD_NAME\$', \$INPUT_ARR\$, null, ['class' => 'form-control']) !!}"; $textField .= '
'; $textField = str_replace('$FIELD_NAME$', $field['fieldName'], $textField); if (sizeof($field['typeOptions']) > 0) { $arr = explode(",", $field['typeOptions']); $inputArr = '['; foreach ($arr as $item) { $inputArr .= " '$item' => '$item',"; } $inputArr = substr($inputArr, 0, strlen($inputArr) - 1); $inputArr .= " ]"; $textField = str_replace('$INPUT_ARR$', $inputArr, $textField); } else { $textField = str_replace('$INPUT_ARR$', '[]', $textField); } $templateData = str_replace('$FIELD_INPUT$', $textField, $templateData); $templateData = self::replaceFieldVars($templateData, $field); return $templateData; } ``` }

anheru88 avatar Jul 02 '15 13:07 anheru88

Hello, Where is located FormFieldsGenerator because i need to use this gist to added more filds type to my application. Thank you very much

butoibogdan avatar Jul 19 '15 08:07 butoibogdan

@butoibogdan, You can find this file in generator's code in your vendor directory. Here is the file.

mitulgolakiya avatar Jul 20 '15 04:07 mitulgolakiya