Type of TextInput numeric()
Hi, I can't figure out what's the the type coming out of a numeric TextInput and have a hard time to test it ... Someone know ?
105 Replies
Can you give an example of what you're trying to do? Do you mean you're trying to do custom validation? a custom rule? What are you doing with the state you've retrieved from the component?
I usually use the lifecycle method on my create or edit record class to dd the form state to see what data is getting output by the form. Both classes have a public method where you can dd $this->form->getState() to see the form values after validation.
This is the TextInput, what type of value this input store ? A string, an int, ... ?
Ok, good to know thx
Ok so after some research its seems like its impossible to have an integer in an input. It always comes out as a string đŠ
That's how livewire works
just cast it? (int)
Yes but casting make it an int when I save the form data
However I'm in a Wizard đ
So if I understand right, I will always have a string in my next step ?
Yep
Great ... I can cancel my entire project đ
ahaha why?
Well I really need an int for placing it in a ->defaultItems of a repeater
If I don't have that the creation of my resource make no sense
just cast it when getting the value?
(int) $get('myValue') ?
Ok, I think I don't understand casting đ
What is this '(int)' ?
That's standard php casting, there is also model casting which does the same thing but on the model level
it's like php 101
https://www.php.net/manual/en/language.types.type-juggling.php
Well I understand Model casting but I didn't know about this one, I'm going to look a that
It's like the first thing you learn when learning php...
Ah, well after multiple years and courses on PHP ... I pretty sure I have never seen that
Like that right ?
Yes
Still doesn't work
Here I should have 4 repeater block but nothing
Is the TextInput reactive?
Nope
It should be ?
How do you expect a change then?
Yes. I wouldnât mention it otherwise. I think itâs called live() now
Did you check the Advanced Forms section?
I need a live() only to $get a value ?
Just to precise is between 2 Wizard steps
the default items load when the form is loaded. not when after the field is updated
you need to add an afterStateUpdated() and $set the repeater with the correct number of items
Ah ok
But how can I $set a certain method on the repeater (defaultItems in this case) ?
I haven't seen it in the doc
Run set with empty values in an array
You don't "set a method". You can only set a form state
You need
live()
to notice a change of the value. Because otherwise it's not updated until you hit submit. But as Dan stated, this isn't the issue here.uuuh ok
I'm lost honestly.
I think a simple $set with the default schema.
No the days wonât work, you need to pass in the data schema.
So:
$set(âtasksâ, [[âtaskâ => ââ],[âtaskâ => ââ]])
Building a loop for the array creation based off the days.
Its doesnt work
Provide your code.
I don't understand how the 'days' repeater can have a new block created by adding a new task to the sub-repeater 'tasks'
Provide your code.
The code is what you said
Provide your code. i.e. the entire code of your wizard.
Stop providing screenshots as per #â
ârules provide the code
In SheetResource.php
This seem far to complicated, but you need to traverse to set the tasks
What do you mean by "traverse" ?
somehting along those lines
Traverse so go through it with ../ because each repeater is it's own statepath.
Quickest way to debug the correct depth you need to go to, add 1 item to the tasks. Then
$original_items = $get('../schedule/tasks');
dd($original_items);
If it is empty, you may need to remove../ or add it if memory serves me correctly
Which show's it's not the correct path to the repeater
Ah
if it was correct then it would be fine. I tested the core here on a single form from a single text input tot update a simple repeater on the same element
I can't manage to fix the issue
I've tried to test the repeater path but nothing
It's in a different step too
yes, so ?
You may need to jump out of the step, I can't remember exactly. But I suggest you install livewire chrome tools and inspect the data structure in the console to ensure you know where you are traversing too. The form is overly complex imho.
Ok. Wdym by overly complex ? I didnt thought it would be so difficult to do such a thing, but I dont know how I can do in a different way xD
Looking at the data structure I don't think you do. But you need to learn this stuff yourself too. I've provide the method that works on a standard form. You just need to work out the correct traversal path for your code to get to that repeater
I think in the error the problem really come from the fact that 'days' is still a string
It is not, Iâve told you what the error is
Days is cast to int in the code.
Yes, sorry ...
So this is the data tree
and what's weird is that schedule is a the same level than days
And when I $get with the path based on this tree its null đ
Oh its probably because there is this sort of id between 'schedule' and 'tasks'
Can you explain a bit more about that ? please
i dont have the time right now, i do think there are plenty of examples online
also there are many knowledgeable people here who also know what im talking about
setting a field when another field is updated is quite common
Ok no problem, but just is it possible to update the defaultItems with afterStateUpdated() ?
defaultitems does not need to be used
you $set the entire content of the repeater in afterstateupdated
so you can add as many items as you want
defaultitems is only relevant when the form is first loaded
Ah ok I'm going to search how to do that thx
I thought that was echo 'Hello World'; đ§
Hence 'Like' đ
@toeknee So do you know why there is this a sort of uuid between the repeaters ? Which is probably stoping me to reach the value I want
Yes, the uuid is the unique ID for the repeater element that livewire uses
But that's just the array key
It shouldn't affect your traversal
Did you install livewire tools for chrome to view the data stack?
Yes, I have this but there is absolutely nothing in it
Click the state icon
I tried to 'select' something but it changed nothing, Idk if I'm that dumb or what đ
Then refresh the page and access the form
still nothing
And you open the console on the page wiht livewire?
Strange working here click the red dot
then click it again
I've tried while recording (red dot) and without and its the same
ofc after refreshing the page, accessing the form ...
I must be cursed đ
Should look something like this, FYI it is all faker data đ
Im am using Edge and the livewire extension... so maybe try that
The problem must come from here
Ahh you have enabled production mode? change to local or dev
I don't know if its related but APP_DEBUG is true and APP_ENV is local
APP_ENV local should be good
Nope its weird
Ahh actually you are on V3. It might not work on V3 đ
Yep its V3
Sorry my bad, But the principle should be the same
Traversal should be fine, although there could be some parent fetchers with v3 introduced. I just haven't used it too much
And yep the dev tools doesn't work, we are waiting for caleb to release livewire/wiretap.
Ok, too bad
Honestly I don't know what to more than that ... except having a good old manual repeater đ
Can you provide the whole resource
and model and I'll take a look.
Yeah no problem,
SheetResource
What's your logic for writing so many functions for the repeaters?
Because right now I'm only working on the CreateRecord (in another file) but when I would work on the edit form (i.e. SheetResource form) I don't have to duplicate the code
but you just use ->form()
Uh ? đ€
public static function form(Form $form): Form
{
return $form
->schema([
]);
}
Is where you build the schema usually
You have built ton's of functions which isn't too bad if you are heavily reusing the code
but it's messy when it's a simple edit/create
(last file) CreateSheet
Are you planning on only using the wizard on create?
Yes
And not using it on edit?
Yep
Ok my bad
I mean its how I see it, the edit would probably be with tabs however
Oh my bad I didnt changed my test before sending evrything ...
There is still my stupid try of double afterStateUpdate with the getDaysHiddenFormField() đ
Passing the days from one step to the other (which in fact don't help me more xD)
(for the model) Sheet