GithubHelp home page GithubHelp logo

Comments (7)

adamgoose avatar adamgoose commented on July 18, 2024 2

No, I feel that providing a default value should take precedence.

from html.

adamgoose avatar adamgoose commented on July 18, 2024

The Form::model() method is designed to allow you to pass nulls into your forms and still have them populate. The way I like to do it is like this:

{!! Form::model($model, [$routeInfo]) !!}

    {!! Form::text('name', isset($model) ? null : 'Default Value', ['class' => 'form-control']) !!}

{!! Form::close() !!}

from html.

Gael42 avatar Gael42 commented on July 18, 2024

Thanks a lot for your answer !

I still do not undetstand why default value is prefered to model value ? it should be the opposite no ?

from html.

Gael42 avatar Gael42 commented on July 18, 2024

May you develop ? no troll, i just really want to understand why

from html.

adamgoose avatar adamgoose commented on July 18, 2024

Here's how I see it...

If you use Form::model() and the provided model value takes precedence, then you have absolutely no way to override that value when using Form::text() or any other method. Thus, you lose control over your form to some extent. In my opinion, that's not acceptable.

Either way, changing the way this works will surely break backwards compatibility.

from html.

Gael42 avatar Gael42 commented on July 18, 2024

Even if it feel strange that a 'default' value is prefered to any another one that make sense, and yes, change that will definitely break backwards compat.

Thanks again for your answer :-)

from html.

nicolasbinet avatar nicolasbinet commented on July 18, 2024

I had the same problem and finished modifying the getValueAttribute

  • First if the default if $name is not provided
  • Get the value that was submitted
  • If not the value from special fields "_token" & "_method" & $model is set ,get the value
  • Else, get the default value
public function getValueAttribute($name, $value = null)
{
    if (is_null($name)) return $value;

    if (! is_null($this->old($name))) {
        return $this->old($name);
    }

    if ($name != '_token' && $name != '_method' && isset($this->model)) {
        return $this->getModelValueAttribute($name);
    }

    if (!is_null($value)) return $value;
}

from html.

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.