Skip to content

Commit

Permalink
Removed LaravelCollective related codes
Browse files Browse the repository at this point in the history
  • Loading branch information
balajidharma committed Jul 28, 2024
1 parent 7c95130 commit d7425a6
Show file tree
Hide file tree
Showing 33 changed files with 449 additions and 271 deletions.
46 changes: 43 additions & 3 deletions config/form-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,63 @@
'error_class' => 'text-danger',
'required_class' => 'required',
'help_block_tag' => 'p',

// Override a class from a field.
//'text' => [
// 'wrapper_class' => 'form-field-text',
// 'label_class' => 'form-field-text-label',
// 'field_class' => 'form-field-text-field',
//]
//'radio' => [
// 'choice_options' => [
// 'wrapper' => ['class' => 'form-radio'],
// 'label' => ['class' => 'form-radio-label'],
// 'field' => ['class' => 'form-radio-field'],
// ]
//],
//
// 'choice' => [
// 'choice_options' => [
// 'wrapper_class' => 'choice-wrapper-class',
// 'label_class' => 'choice-label-class',
// 'field_class' => 'choice-field-class'
//
// # For choice type you may overwrite default choice options for each variant (checkbox, radio or select)
// 'checkbox' => [
// 'wrapper_class' => 'choice-checkbox-wrapper-class',
// 'label_class' => 'choice-checkbox-label-class',
// 'field_class' => 'choice-checkbox-field-class',
// ]
// ]
//]

// Templates
'templates' => [
'datalist' => 'laravel-form-builder::datalist',
'form' => 'laravel-form-builder::form',
'text' => 'laravel-form-builder::text',
'textarea' => 'laravel-form-builder::textarea',
'button' => 'laravel-form-builder::button',
'buttongroup' => 'laravel-form-builder::buttongroup',
'radio' => 'laravel-form-builder::radio',
'radios' => 'laravel-form-builder::radios',
'checkbox' => 'laravel-form-builder::checkbox',
'checkboxes' => 'laravel-form-builder::checkboxes',
'select' => 'laravel-form-builder::select',
'choice' => 'laravel-form-builder::choice',
'repeated' => 'laravel-form-builder::repeated',
'child_form' => 'laravel-form-builder::child_form',
'collection' => 'laravel-form-builder::collection',
'static' => 'laravel-form-builder::static',
],

// Remove the laravel-form-builder:: prefix above when using template_prefix
'template_prefix' => '',

'default_namespace' => '',

'custom_fields' => [
// 'datetime' => App\Forms\Fields\Datetime::class
],
],
'plain_form_class' => \BalajiDharma\LaravelFormBuilder\Form::class,
'form_builder_class' => \BalajiDharma\LaravelFormBuilder\FormBuilder::class,
'form_helper_class' => \BalajiDharma\LaravelFormBuilder\FormHelper::class,
];
7 changes: 1 addition & 6 deletions resources/views/button.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
<?php } ?>

<button type="<?= $type ?>"
<?php
if (isset($options['attr']) && $type != 'hidden') {
foreach ($options['attr'] as $attr => $val) { ?>
<?php echo $attr.'="'.$val.'"'; ?>
<?php }
} ?>
<?= render_form_attributes($options['attr'] ?? []); ?>
><?= $options['label'] ?></button>
<?php include helpBlockPath(); ?>

Expand Down
4 changes: 3 additions & 1 deletion resources/views/buttongroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<?php } ?>

<?php foreach ($options['buttons'] as $button) { ?>
<?= Form::button($button['label'], $button['attr']) ?>
<button type="<?= $type ?>"
<?= render_form_attributes($options['attr'] ?? []); ?>
><?= $options['label'] ?></button>
<?php } ?>

<?php if (! $options['splitted']) { ?>
Expand Down
20 changes: 14 additions & 6 deletions resources/views/checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
<?php } ?>

<?php if ($showField) { ?>
<?= Form::checkbox($name, $options['value'], $options['checked'], $options['attr']) ?>

<?php if ($showLabel && $options['label'] !== false && $options['label_show']) { ?>
<?= Form::customLabel($name, $options['label'], $options['label_attr']) ?>
<?php } ?>

<label
<?php
if (isset($options['label_attr'])) {
foreach ($options['label_attr'] as $attr => $val) { ?>
<?php echo $attr.'="'.$val.'"'; ?>
<?php }
} ?>
>
<input type="checkbox" name="<?= $name ?>" value="<?= $options['value'] ?>" <?= $options['checked'] ? 'checked' : '' ?>
<?= render_form_attributes($options['attr'] ?? []); ?>
/>
<?= $options['label'] ?></label>
<?php include helpBlockPath(); ?>
<?php } ?>
<?php }
}?>

<?php include errorBlockPath(); ?>

Expand Down
47 changes: 0 additions & 47 deletions resources/views/checkboxes.php

This file was deleted.

2 changes: 1 addition & 1 deletion resources/views/child_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<?php } ?>

<?php if ($showLabel && $options['label'] !== false && $options['label_show']) { ?>
<?= Form::customLabel($name, $options['label'], $options['label_attr']) ?>
<?php include labelBlockPath() ?>
<?php } ?>

<?php if ($showField) { ?>
Expand Down
46 changes: 46 additions & 0 deletions resources/views/choice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php if ($showLabel && $showField) { ?>
<?php if ($options['wrapper'] !== false) { ?>
<div <?= $options['wrapperAttrs'] ?> >
<?php } ?>
<?php } ?>

<?php /** label rendering section */ ?>
<?php if ($showLabel && $options['label'] !== false && $options['label_show']) { ?>
<?php if (array_key_exists('label_template', $options) && $options['label_template']) { ?>
<?= view($options['label_template'], get_defined_vars())->render(); ?>
<?php } else { ?>
<?php include labelBlockPath(); ?>
<?php } ?>
<?php } ?>

<?php if ($showField) { ?>
<div
<?php
if (isset($options['choices_wrapper'])) {
foreach ($options['choices_wrapper'] as $attr => $val) { ?>
<?php echo $attr.'="'.$val.'"'; ?>
<?php }
} ?>
>

<?php /** choice rendering section */ ?>
<?php foreach ((array) $options['children'] as $child) { ?>
<?= $child->render($options['choice_options'], true, true, false) ?>
<?php } ?>

<?php if (isset($options['choices_wrapper'])) { ?>
</div>
<?php } ?>

<?php include helpBlockPath(); ?>

<?php } ?>


<?php include errorBlockPath(); ?>

<?php if ($showLabel && $showField) { ?>
<?php if ($options['wrapper'] !== false) { ?>
</div>
<?php } ?>
<?php } ?>
2 changes: 1 addition & 1 deletion resources/views/collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<?php } ?>

<?php if ($showLabel && $options['label'] !== false && $options['label_show']) { ?>
<?= Form::customLabel($name, $options['label'], $options['label_attr']) ?>
<?php include labelBlockPath() ?>
<?php } ?>

<?php if ($showField) { ?>
Expand Down
7 changes: 0 additions & 7 deletions resources/views/datalist.php

This file was deleted.

10 changes: 4 additions & 6 deletions resources/views/form.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php if ($showStart) { ?>
<form action="<?= $formOptions['url'] ?>" method="<?= $formOptions['method'] ?>"
<?php
if (isset($formOptions['attr'])) {
foreach ($formOptions['attr'] as $attr => $val) { ?>
<?php echo $attr.'="'.$val.'"'; ?>
<?php }
} ?>
<?php if (isset($formOptions['files'])) { ?>
enctype="multipart/form-data"
<?php } ?>
<?= render_form_attributes($formOptions['attr'] ?? []); ?>
>
<?php } ?>

Expand Down
10 changes: 10 additions & 0 deletions resources/views/label.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php if ($showLabel && $options['label'] !== false && $options['label_show']) { ?>
<label for="<?= $name ?>"
<?php
if (isset($options['label_attr'])) {
foreach ($options['label_attr'] as $attr => $val) { ?>
<?php echo $attr.'="'.$val.'"'; ?>
<?php }
} ?>
><?= $options['label'] ?></label>
<?php } ?>
7 changes: 5 additions & 2 deletions resources/views/radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
<?php } ?>

<?php if ($showField) { ?>
<?= Form::radio($name, $options['value'], $options['checked'], $options['attr']) ?>
<input type="radio" name="<?= $name ?>" value="<?= $options['value'] ?>"
<?= $options['checked'] ? 'checked' : '' ?>
<?= render_form_attributes($options['attr'] ?? []); ?>
/>

<?php if ($showLabel && $options['label'] !== false && $options['label_show']) { ?>
<?= Form::customLabel($name, $options['label'], $options['label_attr']) ?>
<?php include labelBlockPath() ?>
<?php } ?>

<?php include helpBlockPath(); ?>
Expand Down
32 changes: 0 additions & 32 deletions resources/views/radios.php

This file was deleted.

28 changes: 25 additions & 3 deletions resources/views/select.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,35 @@
<?php } ?>
<?php } ?>

<?php /** label rendering section */ ?>
<?php if ($showLabel && $options['label'] !== false && $options['label_show']) { ?>
<?= Form::customLabel($name, $options['label'], $options['label_attr']) ?>
<?php if (array_key_exists('label_template', $options) && $options['label_template']) { ?>
<?= view($options['label_template'], get_defined_vars())->render(); ?>
<?php } else { ?>
<?php include labelBlockPath(); ?>
<?php } ?>
<?php } ?>

<?php if ($showField) { ?>
<?php $emptyVal = $options['empty_value'] ? ['' => $options['empty_value']] : null; ?>
<?= Form::select($name, (array) $emptyVal + $options['choices'], $options['selected'], $options['attr'], $options['option_attributes']) ?>
<select name="<?= $name ?>"
<?= render_form_attributes($options['attr'] ?? []); ?>
>
<?php if ($options['empty_value']) { ?>
<option value=""><?= $options['empty_value'] ?></option>
<?php } ?>
<?php foreach ($options['choices'] as $key => $value) { ?>
<option value="<?= $key ?>" <?= in_array($key, (array) $options['selected']) ? 'selected = "selected"' : '' ?>
<?php
if (isset($options['option_attributes'])) {
foreach ($options['option_attributes'] as $attr => $val) { ?>
<?php echo $attr.'="'.$val.'"'; ?>
<?php }
} ?>
><?= $value ?></option>
<?php } ?>
</select>

<?php include helpBlockPath(); ?>
<?php } ?>

Expand All @@ -20,4 +42,4 @@
<?php if ($options['wrapper'] !== false) { ?>
</div>
<?php } ?>
<?php } ?>
<?php } ?>
2 changes: 1 addition & 1 deletion resources/views/static.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<?php } ?>

<?php if ($showLabel && $options['label'] !== false && $options['label_show']) { ?>
<?= Form::customLabel($name, $options['label'], $options['label_attr']) ?>
<?php include labelBlockPath() ?>
<?php } ?>

<?php if ($showField) { ?>
Expand Down
Loading

0 comments on commit d7425a6

Please sign in to comment.