Code Monkey home page Code Monkey logo

Comments (12)

kristijanhusak avatar kristijanhusak commented on May 27, 2024

Do you want to add directives as attributes or as totally different element/tag ?

from laravel-form-builder.

mikeerickson avatar mikeerickson commented on May 27, 2024

Complete new tag, eg.

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on May 27, 2024

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.

mikeerickson avatar mikeerickson commented on May 27, 2024

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.

kristijanhusak avatar kristijanhusak commented on May 27, 2024

Give me the html that you expect from datepicker.

from laravel-form-builder.

mikeerickson avatar mikeerickson commented on May 27, 2024

@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.

mikeerickson avatar mikeerickson commented on May 27, 2024

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.

mikeerickson avatar mikeerickson commented on May 27, 2024

Hold on, I will get a screenshot

from laravel-form-builder.

mikeerickson avatar mikeerickson commented on May 27, 2024

Here is an example of what directive would ouput

http://d.pr/i/qhKe

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on May 27, 2024

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.

mikeerickson avatar mikeerickson commented on May 27, 2024

@kristijanhusak Thanks, I will give it a whirl and see how it goes. Looks pretty straight forward to me.

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.