Comments (12)
Do you want to add directives as attributes or as totally different element/tag ?
from laravel-form-builder.
Complete new tag, eg.
from laravel-form-builder.
Just follow instructions for creating custom types https://github.com/kristijanhusak/laravel-form-builder#custom-fields . In case that you want to modify the defaults just publish the views and modify as you want.
from laravel-form-builder.
Here is an example of what I would do (not sure how to set the startDate property but it should come from the Company model)
public function buildForm()
{
$this
->add('active', 'checkbox', ['label' => 'Active'])
->add('name', 'text', ['label' => 'Name:'])
->add('address', 'text', ['label' => 'Address:'])
->add('city', 'text', ['label' => 'City:'])
->add('state', 'text', ['label' => 'State:'])
->add('zip', 'text', ['label' => 'Zip Code:'])
->add('startDate', 'datepicker', ['id' => 'startDate', 'startDate' => '2014-11-09'])
->add('phone', 'text', ['label' => 'Phone:'])
->add('county', 'text', ['label' => 'County:'])
->add('Save', 'submit', [
'attr' => ['class' => 'btn btn-primary']
]);
}
from laravel-form-builder.
Give me the html that you expect from datepicker
.
from laravel-form-builder.
@kristijanhusak OK, I see what you are doing for the custom field, easy enough. I will have to create custom classes for any angular directive I use (as an element level directive)
I am still puzzled how to pass along the model value to the appropriate directive attribute. Any clues?
from laravel-form-builder.
Ya, that is where I am having trouble getting github issue to accept my end result. I cant seem to get it to appear (it was in my original post).
from laravel-form-builder.
Hold on, I will get a screenshot
from laravel-form-builder.
Here is an example of what directive would ouput
from laravel-form-builder.
For <datepicker>
create custom field type, and for passing the data as attributes, use attr
on the field when adding it. This is how would i do it. Hope it helps:
<?php
// Custom field location
use Kris\LaravelFormBuilder\Form;
use Kris\LaravelFormBuilder\Fields\FormField;
class Datepicker extends FormField
{
public function getTemplate()
{
return 'fields/datepicker'; // views/fields/datepicker.blade.php, get template view structure from default fields
}
public function render(array $options = [], $showLabel = true, $showField = true, $showError = true)
{
$options['all_attrs'] = $this->formHelper->prepareAttributes($options['attr']);
return parent::render($options, $showLabel, $showField, $showError);
}
}
// Forms location
class MainForm extends Form {
public function buildForm()
{
$this->add('startDate', 'datepicker', [
'attr' => ['id' => 'startDate', 'startDate' => '2014-11-09', 'ng-model' => 'post-or-whatever', 'ng-somedata' => $this->model->somedata ]
]);
}
}
// Contorller
class MainController extends Controller {
public function index()
{
$model = Post::find(1);
$form = \FormBuilder::create('MainForm', [ 'model' => $model ]);
}
}
// views/fields/datepicker.php
<?php if ($showField): ?>
<datepicker <?= $options['all_attrs'] ?>></datepicker>
<?php endif; ?>
from laravel-form-builder.
@kristijanhusak Thanks, I will give it a whirl and see how it goes. Looks pretty straight forward to me.
from laravel-form-builder.
No problem. You can even create some kind of dynamic custom field like this:
<?php
// Forms location
class MainForm extends Form {
public function buildForm()
{
$this->add('startDate', 'custom_tag', [
'tag' => 'project',
'attr' => ['id' => 'startDate', 'startDate' => '2014-11-09', 'ng-model' => 'post-or-whatever', 'ng-somedata' => $this->model->somedata ]
]);
}
}
// views/fields/custom_tag.php
// Creates <project id="..."></project> in this situation, but can be modified with "tag"
<?php if ($showField): ?>
<<?= $options['tag'] ?> <?= $options['all_attrs'] ?>></<?= $options['tag'] ?>>
<?php endif; ?>
from laravel-form-builder.
Related Issues (20)
- Remove laravelcollective/html HOT 11
- v1.50 breaks field type collection HOT 5
- BUG: radio buttons chioce type returns an array HOT 5
- Feature request: Switching between classes by theme HOT 9
- Please change CHANGELOG and Releases HOT 3
- Select option for null values HOT 3
- Multiple file upload HOT 1
- Feature request: Add conditional field HOT 3
- Add Fieldset type HOT 3
- Compatibility Laravel 9 ? HOT 2
- getFieldValues() default value instead of null HOT 2
- Default placeholder for entity type(Field::ENTITY). HOT 1
- Radio button has problem HOT 2
- Using entity how we can display format with multiple columns HOT 1
- Collection of templated form HOT 2
- Error: count(): Argument #1 ($value) must be of type Countable|array, Mekongdelta\Slug\Models\Slug given HOT 5
- Validate without request HOT 10
- Invalid pattern for input
- At least one "choice" checkboxes required HOT 2
- Support for Laravel 11 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-form-builder.