Code Monkey home page Code Monkey logo

Comments (3)

kristijanhusak avatar kristijanhusak commented on May 24, 2024

By default button type is using a label for name, so this is in template:

<?= Form::button($options['label'], $options['attr']) ?>

There are several solutions:

  1. Publish views and update button template to something like this:
<?php if ($options['default_value']): ?>
<?= Form::button($options['default_value'], $options['attr']) ?>
<?php else: ?>
<?= Form::button($options['label'], $options['attr']) ?>
<?php endif; ?>
  1. Create custom button type:

Template: fields.custom_button

<?= Form::button($options['default_value'], $options['attr']) ?>

Field Class:

use Kris\LaravelFormBuilder\Fields\FormField;

class CustomButton extends FormField {
    public function getTemplate()
    {
        return 'fields.custom_button';
    }
}

Form Class:

class MyForm extends Form
{
    public function buildForm()
    {
        // This can be added also in published configuration in config/laravel-form-builder.php
        $this->addCustomField('custom_button', 'App\Forms\Fields\CustomButton');
        $this->add('buttons', 'collection', [
            'type' => 'custom_button',
            'property' => 'name'   // This is pulled from model value , [ ['name' => 'button1'], ['name' => 'button2'])
       ]);
    }
}

I would probably go with 1st solution because it's much simpler.

from laravel-form-builder.

jaroslawziolkowski avatar jaroslawziolkowski commented on May 24, 2024

Thank you, I knew that I should change template but not what parameter use as label.

Maybe you can set to documentation all standard variables available in templates? Probably it will be useful for more people.

from laravel-form-builder.

kristijanhusak avatar kristijanhusak commented on May 24, 2024

Yeah I planned to do that, just didn't have time. Will do it when i catch up.

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.