Git Product home page Git Product logo

laravel-bootstrap-4-forms's Introduction

laravel-bootstrap-4-forms's People

Contributors

1e4 avatar ataylor32 avatar bumerang07 avatar codetestmg avatar edoong avatar edpogi avatar fchalal avatar ilyes-kechidi avatar innovaweb-dev avatar jhermans76 avatar joseneto-fixeads avatar kingwkb avatar lakerobin avatar marcusgaius avatar netojose avatar notarun avatar pascalbaljet avatar snickbit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-bootstrap-4-forms's Issues

Could not find package netojose/laravel-bootstrap-4-forms

Hi,

When I try to install your package from composer I get the following error:

Could not find package netojose/laravel-bootstrap-4-forms at any version for your minimum-stability (dev). Check the package spelling or your minimum-stability

It looks like you have a type mismatch in you composer.json file:

"name": "netojose/laravel-bootstrap4-forms",

should be:

"name": "netojose/laravel-bootstrap-4-forms",

The package itself seems to work as aspected except for the selectbox:

All the options of the selectbox gets the 'selected' property after populating.

Some Questions:

  1. I like to add a default value to the select box.
    Something like 'Please select a category'.
  2. Could'nt find the option to add an 'old value' to the selectbox so an item is selected when using the selectbox in an edit form.

Is it possible to add those features?

Thank you for this great package!

Richard

Autocomplete support

As per the spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofill there are limited values of the autocomplete that are valid.

There are two problems

  1. The plugin automatically generates autocomplete values for all text input elements, setting it equal to the name attribute, many of which may be invalid as per the spec. It may also force the browser to store the values by default, which may not be what developer wants.

  2. The autocomplete value cannot be turned off or user specified. If we pass it as an attribute, the attribute value gets overwritten by name value.

Custom class and/or attributes for the .form-group div?

Looking at the FormBuilder class' _renderWarpperCommomField method (that method's name has a typo, by the way), it appears that the <div> is hard-coded to use <div class="form-group ">. It would be nice to be able to add another class or even a custom attribute like id or data-foo or whatever.

Add suppor for Date object as default for date field

I'm trying to set the DateTime object as param as default for the Form::date() helper, without success.

$date = new \DateTime('tomorrow');
{!! Form::date('date', 'Matches for date:', $date) !!}

Should we add suport for that?

Current workardound is $date->format('Y-m-d'), but should not.

setting input default value

text inputs are not accepting value as third parameter

i tried
{!! Form::text('title', 'Title','value') !}}

but the value attribute has not been set

Element order

Is possible to chage order of rendered elements - first input and second label?

<div class="form-label-group">
<input type="email" id="inputEmail" class="form-control" placeholder="Email address">
<label for="inputEmail">Email address</label>
</div>

Model and many-to-many relations in select field

Hi @netojose

I'm building a form for a model (Venue), which can have multiple tags (many-to-many relationship)
When I'm editing a form, I would like to see which tags that are already added to the venue model.

To do so, it seems like you need to have a very specific data structure:

{!! Form::select('tags', 'Select tags', [1 => 'Some tag', 2 => 'Another tag'])->multiple() !!}

This means, that you cannot do something like this:

// Controller
$tags = Tag::all();
return view('venue.edit', ['tags' => $tags]);

// Blade
{!! Form::select('tags', 'Select tags', $tags)->multiple() !!}

Instead you need to do this to accomplish the correct data structure and have existing relationships selected:

// edit method in controller
$model = $venue->toArray();
$model['tags'] = $venue->tags->pluck('name', 'id')->all();

$data = [
    'model' => $model,
    'tags' => Tag::all()->pluck('name', 'id')->all()
];

return view('venue.edit', $data);

Is this by design how you should handle such forms? E.g. forms which has relationships with other models? Like a blog post with tags?

fill() isn't populating checkboxes

Here is my form:

{!! Form::open()->route('posts.update', [$post->id])->fill($post)->patch() !!}
{!! Form::text('title', 'Title')->attrs(['maxlength' => '255'])->required() !!}
{!! Form::textarea('body', 'Body')->attrs(['class' => 'wysiwyg'])->required() !!}
<input type="hidden" name="allow_comments" value="0">
{!! Form::checkbox('allow_comments', 'Allow comments?', '1')->wrapperAttrs(['class' => 'wrapper-allow_comments']) !!}
{!! Form::submit('Update Post') !!}
{!! Form::close() !!}

The allow_comments field is a boolean field, as you can see in the migration file:

$table->boolean('allow_comments');

When I go to edit a post that has its allow_comments field set to 1, the checkbox renders as unchecked. I would expect it to render as checked.

patch() not working correctly

Here is my form:

{!! Form::open()->route('posts.update', [$post->id])->fill($post)->patch() !!}
{!! Form::text('title', 'Title')->attrs(['maxlength' => '255'])->required() !!}
{!! Form::textarea('body', 'Body')->attrs(['class' => 'wysiwyg'])->required() !!}
<input type="hidden" name="allow_comments" value="0">
{!! Form::checkbox('allow_comments', 'Allow comments?', '1')->wrapperAttrs(['class' => 'wrapper-allow_comments']) !!}
{!! Form::submit('Update Post') !!}
{!! Form::close() !!}

The <form> tag that gets generated by the above code starts with <form method="patch", so the browser doesn't handle it correctly. Because of that, I need to remove ->patch() and add this to my form:

<input type="hidden" name="_method" value="patch">

Problemas com select e relacionamentos

Estou tentando criar um select multiple que define as roles que meus usuários possuem.
{!! Form::select('role_ids[]', $roleOptions, __('app.users.labels.roles'))->params(['multiple' => true]) !!}

Porém no edit utilizando a função fill()
{!! Form::open()->put()->url('/users/' . $user->id . '/edit')->fill($user) !!}

O form gerado coloca todas as opções do select como selecionadas, ao invés das opções que o usuário possui, sendo que Role é um relacionamento (N para N).
Isto seria algum tipo de bug ou erro, ou existe alguma configuração para solucionar este problema?

Color classes doesn't get added

Hi @netojose

I have tried using the example from the docs:

{!!Form::submit('Awesome button')->id('my-btn')->disabled()->danger()->lg()!!}

The id(), disabled() and lg() methods works, except danger() (or color('danger)), it just doesn't work. Also, the btn class doesn't seem to be added either.

I have tried looking through the source, but I can't see exactly where the problem is.

wrapperAttrs doesn't work with checkboxes

Here is my form:

{!! Form::open()->route('posts.update', [$post->id])->fill($post)->patch() !!}
{!! Form::text('title', 'Title')->attrs(['maxlength' => '255'])->required() !!}
{!! Form::textarea('body', 'Body')->attrs(['class' => 'wysiwyg'])->required() !!}
<input type="hidden" name="allow_comments" value="0">
{!! Form::checkbox('allow_comments', 'Allow comments?', '1')->wrapperAttrs(['class' => 'wrapper-allow_comments']) !!}
{!! Form::submit('Update Post') !!}
{!! Form::close() !!}

The wrapper that gets generated for the allow_comments field by the above code is <div class="form-check">. Notice that it didn't apply my wrapper-allow_comments class.

Checkboxes are marked :checked when chained value doesn't match checkbox value.

A checkbox is marked checked just so long as there is ANY value returned from _getValue() and the type is checkbox. Is this right? This is occurring around line 778 of the FormBuilder.php:

if (in_array($this->_type, ['radio', 'checkbox'])) {
    $value = $this->_getValue();
    if (
            $value && (
            $this->_type === 'checkbox' || $this->_type === 'radio' && $value === $this->_meta['value']
            )
    ) {
            $props['checked'] = true;
    }
}

Perhaps this needs to be simplified to just check value matches the _meta['value']? (since we know it is of type radio or checkbox already)

if (in_array($this->_type, ['radio', 'checkbox'])) {
    $value = $this->_getValue();
    if ($value && $value === $this->_meta['value'] ) {
        $props['checked'] = true;
    }
}

Radios require both passed in and chained value.

I'm trying to set the default value of a radio with this (simplified) snippet by chaining ->value():

    {!! Form::radio("gender", "Gender")->value($value) !!}

Instead of passing in the value directly to the radio method.

    {!! Form::radio("gender", "Gender", $value) !!}

I see in the FormService (line~892), that it is only checking for the passed in value.

    private function _checkboxRadio($type, $name, $label, $value, $default): FormService
    {
        $inputValue = $value === null ? $name : $value;

        if ($default) {
            $default = $inputValue;
        }

        return $this->_set('meta', ['value' => $inputValue])->type($type)->name($name)->label($label)->value($default);
    }

The result of the chaining approach is that the radio value is set to the form name. It doesn't later check if another value was provided by the chaining method.

Can this be supported?

Perhaps if this _checkboxRadio was moved to the FormBuilder and there is access to _getValue() we could add another check there?

Thank you!

Usable with Lumen ?

Hi,

Can I use laravel-bootstrap-4-forms with Lumen ?
Because, I don't know how install it.

Thanks for your help.

Add support for <input type="datetime-local">

Support on desktop browsers isn't that great (source), but it still makes sense to use in some projects. I would submit a PR for this myself, but it's not exactly straightforward due to the hyphen in datetime-local. I would really appreciate this input type being available in this excellent package!

Invalid selected state for select control

I found a bug with select control.

You can look at FormService.php file, line 371.

Current code:

 foreach ($this->_props['options'] as $value=> $label){
            $checked = $value== $value ? ' selected' : '';
            $options .= '<option value="'.$value.'"'.$checked.'>'.$label.'</option>';
        }

It should be:

foreach ($this->_props['options'] as $option => $label){
            $checked = $option == $value ? ' selected' : '';
            $options .= '<option value="'.$option.'"'.$checked.'>'.$label.'</option>';
        }

Please merge this code to the next release.
Also, do you have a plan to support select with multiple?

Thanks

required attribute does not work

Setting the required attribute by calling required method does not generate the corresponding code.

{!!Form::text('name', 'Name')->required()!!}

generates

<div class="form-group ">
    <label for="name">Name</label>
    <input type="text" name="name" autocomplete="name" id="name" class="form-control">
</div>

 
required attribute is missing.

Field attributes are being applied to both the field and its label

Here is my form:

{!! Form::open()->route('posts.update', [$post->id])->fill($post)->patch() !!}
{!! Form::text('title', 'Title')->attrs(['maxlength' => '255'])->required() !!}
{!! Form::textarea('body', 'Body')->attrs(['class' => 'wysiwyg'])->required() !!}
<input type="hidden" name="allow_comments" value="0">
{!! Form::checkbox('allow_comments', 'Allow comments?', '1')->wrapperAttrs(['class' => 'wrapper-allow_comments']) !!}
{!! Form::submit('Update Post') !!}
{!! Form::close() !!}

The <label> tag that gets generated for the title field by the above code is <label maxlength="255" for="inp-title" class="">Title</label> (notice it has maxlength="255"). Likewise, the <label> tag that gets generated for the body field by the above code is <label class="wysiwyg" for="inp-body">Body</label> (notice it has class="wysiwyg"). I would expect these attributes to be applied only to the fields, not their labels.

Custom attributes not work

netojose/laravel-bootstrap-4-forms 2.0.5

{!!Form::text('name', 'Name')->attrs(['data-foo' => 'bar', 'rel'=> 'baz'])!!}
{!!Form::open()->attrs(['data-foo' => 'bar', 'rel'=> 'baz'])!!}

not work. Please check.

FormBuilder::errors() issue

Hello!

I installed your package on Laravel 5.4.36 but got next error during render input elements:

{!! Form::open()->url(route('users-update')) !!} // Ok 
{!! Form::close() !!} // Ok

But any attempt to call {!! Form::text('name', 'Name') !!} causes next error

Method NetoJose\Bootstrap4Forms\FormService::__toString() must not throw an exception, caught TypeError: Return value of NetoJose\Bootstrap4Forms\FormBuilder::errors() must be an instance of Illuminate\Support\MessageBag, instance of Illuminate\Support\ViewErrorBag returned

And could you insert information about the minimal supported version of PHP in the readme?
Because you wrote that this package available for Laravel framework started from v5.4 (PHP >= 5.6.4) and in the same moment you used iterable typehint that available from php 7.1 (official documentation)
public function options(iterable $options = [], string $valueKey = null, string $idKey = null): FormService

Thank you for your work!

Exception Thrown for Arrays

When I use this code:

{!! Form::text('title', 'Title') !!}

I get this output:

<div class="form-group "><label for="title">Title</label><input type="text" name="title" id="title" class="form-control"></div>

If somebody decides to mess with the HTML using their browser's developer tools, they could change name="title" to name="title[]" and submit the form. If the form doesn't pass validation and the user gets redirected back to the form, the following exception is thrown:

Method NetoJose\Bootstrap4Forms\FormService::__toString() must not throw an exception, caught ErrorException: htmlspecialchars() expects parameter 1 to be string, array given

Granted, this is probably an uncommon scenario, but nevertheless it could happen.

Form Facade alias

Laravel version: 5.6

After being installed, your package's alias is overriding my Form Collective package. I've tried to inform an alias but without effect.

// config/app.php
/*
 * Package Aliases...
*/
'Bootstrap4Form' => NetoJose\Bootstrap4Forms\Bootstrap4FormsFacade::class,
'Form' => Collective\Html\FormFacade::class,

Trying to use {!! Form:: !!} is reaching your package instead of Collective.

How can i solve?

Version 2.0.3 is not installed correctly

  • Laravel 5.6
  • composer require netojose/laravel-bootstrap-4-forms
  • When loading a view: Class 'NetoJose\Bootstrap4Forms\FormService' not found

If I change to version 2.0.2 in composer.json, it works fine!

Multiple forms on a page

Hey,

I have multiple forms on a page, whenever I submit one, I get the validation for the other as well, is there anyway to avoid this other than having them on separate pages?

image

    <div class="card mb-3">
        <div class="card-header">
            Update your email
        </div>
        <div class="card-body">
            {!! Form::open()->route('account.email')->post() !!}
            {!! Form::text('email', 'New Email')->type('email') !!}
            <p>
                Upon updating your current email, your account will require validation before actions can be made
            </p>
            {!! Form::submit('Update Email') !!}
            {!! Form::close() !!}
        </div>
    </div>

    <div class="card">
        <div class="card-header">
            Update your Password
        </div>
        <div class="card-body">
            {!! Form::open()->route('account.password')->post() !!}
            {!! Form::text('new_password', 'New Password')->type('password') !!}
            {!! Form::text('new_password_confirmation', 'New Password Confirmation')->type('password') !!}
            {!! Form::text('current_password', 'Current Password')->type('password') !!}
            {!! Form::submit('Update Password') !!}
            {!! Form::close() !!}
        </div>
    </div>

FormService.php problem

Hi

I just test your package with my laravel 5.4 and I've got this error no matter what code I add to my page :

syntax error, unexpected ':', expecting ';' or '{'
in FormService.php line 65

Do you know how to fix that ?

Thank

Add Custom Class in Input Field

when I add custom class using param, it doesn't validate the field

`
{!!Form::text('name', 'Name')->params(['class' => 'form-control map-input'])!!}

`

Button appearance broken in 2.0.2

In 2.0.2 buttons are being rendered with the form-control class, which makes them 100% width. They also don't seem to respond to the color ('warning', 'danger', etc.) or size ('sm', 'lg', etc.) classes.

// all of these give me full-width, white button
Form::submit('Update config')
Form::submit('Update config', 'primary', 'lg')
Form::button('Update config', 'primary', 'lg')

Is this related to some of the refactoring in 2.0.2?

edit: downgrading to 2.0.0 does fix the first one above. the others may be related to #22

Support for html5 text types

It appears that only number, email and range types are available.

Is there a way to create a input with type of say url or tel?

Checkbox, Radio button renders wrong selected state

In controller I use: $model->active = $request->has('active')
So the real value of model is boolean type: 0 or 1.

In your code, you checked:
$checked = $this->_getValue() == $this->_props['value'] ? 'checked' : null;

In fact, the _getValue() returns 1 while _props['value'] returns 'on' so it never set to selected

Please update this repository when you have a chance. Thanks for your hard work!

Input elements with fa icon

Hello,

I would like a question.
I would liket to use the calendar icon with datepicker on a form input tag like this:
image
How can I do that?
Is it possible?

Thank you for your answear.
Arpad88

"dot" syntax in names

netojose/laravel-bootstrap-4-forms 2.0.6

I use dimsav/laravel-translatable.

Form fields:

{!! Form::text('ru[title]', 'Title RU', $presentation->translateOrNew('ru')->title) !!}
{!! Form::text('en[title]', 'Title EN', $presentation->translateOrNew('en')->title) !!}
...

Validation rules:

    public function rules()
    {
        return [
            'ru.title'      => 'required|string|max:255',
            'en.title'      => 'string|max:255',
            ...
        ];
    }

If errors occur, data is returned to form with rules names, "dot" syntax is used.
ru.title != ru[title] and field ru[title] reset value and does not show an error.

Is there any solution for this problem?

File input class should be "form-control-file"

{!! Form::file('logo','Logo') !!}  

<div class="form-group">
<label for="logo">Logo</label>
<input name="logo" autocomplete="logo" id="logo" class="form-control" type="file">
</div>

Bootstrap doc: For file inputs, swap the .form-control for .form-control-file.

Possible to disable is-valid class?

I'm wondering if there's a way to disable adding the is-valid class automatically when the form is submitted and has errors? I'm only interested in displaying the errors and is-invalid class.

Select - all options receive 'selected' when no value present

When generating a select box, and using it with no previous input from the request (e.g. in a "create new" scenario), all options receive the 'checked' flag, which results in the last option being the selected option by default.

I think I have located the problem and will try and submit a pull request shortly.

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.