Hello world !!!
How do I assign a default value to an input tag in livewire?
My code:
<input name="amount" type="number" value="{{ $invoice->left() }}" class="form-control" step="0.01" min="0" placeholder="{{ $invoice->left() }}" wire:model.lazy="values.{{ $invoice->id }}.amount">
The function $invoice->left()
works fine, the palceholder show correct values,
the "value" in the HTML view shows <input name="amount" type="number" **value="-1140.52"** class="form-control" step="0.01" min="0" placeholder="-1140.52" wire:model.lazy="values.5852.amount">
, but no value is displayed in the browser.
Removing "placeholder" does not have the desired effect.
Any hints? Need more info?
TIA
Wayne
You defined the minimum value for the field to be 0. So it's never going to show you a negative number, remove min="0"
Thank You alen for this tip.
I removed min="0"
but it did not
have any effect. I also removed the
'placeholder' and 'step' entries.
Now I have:
<input name="amount" type="number" value="{{ $invoice->left() }}" class="form-control" wire:model.lazy="values.{{ $invoice->id }}.amount">
The browser´s code inspector shows:
<input name="amount" type="number" value="655.85" class="form-control" wire:model.lazy="values.5705.amount">
The page in the the browser shows an empty input. Somewhere Laravel/Livewire seem to block the value.
Regards
Wayne
wire:model=“someProperty”
will bind the component property $someProperty
to the value a the input field. So if $someProperty
has no value, the input won’t either.
Does $values[5705][‘value’]
have a value?
Maybe initialise $values
in the component class?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community