this post was submitted on 30 Sep 2023
3 points (100.0% liked)

Learn Programming

1625 readers
1 users here now

Posting Etiquette

  1. Ask the main part of your question in the title. This should be concise but informative.

  2. Provide everything up front. Don't make people fish for more details in the comments. Provide background information and examples.

  3. Be present for follow up questions. Don't ask for help and run away. Stick around to answer questions and provide more details.

  4. Ask about the problem you're trying to solve. Don't focus too much on debugging your exact solution, as you may be going down the wrong path. Include as much information as you can about what you ultimately are trying to achieve. See more on this here: https://xyproblem.info/

Icon base by Delapouite under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS
 

I'm currently having trouble with the phone component I'm writing. To be extra vague about it, on my onChange, I'm using a function to move to the next text box. However, when I use my data handler function to raise the value to the parent, it doesn't work. In addition, by adding my data handler to the individual text boxes, it breaks my next Box function.

//dataHandler => raises state data to parent
//nextBox => moves focus to next text box 
 
//onChange should be here
 {
    dataHandler(dataProp, e); 
    nextBox(1);
} />

In the code above, either nextBox works alone, or if I add my handler, then neither work.

I'm also wondering about practices. On other forms, I put this type of handler on single boxes, and it works fine. Since my phone input component has multiple boxes, I'm thinking that onChange won't work exactly the same regardless.

Any advice, tips, or need to know info?

Ps: I'm on mobile, so I greatly simplified the code I'm using, and the formatting is wonky. Assume that there's an onChange before the brackets with an (e) =>. My app or lemmy is deleting it on submission.

you are viewing a single comment's thread
view the rest of the comments
[–] Decide@programming.dev 1 points 1 year ago* (last edited 1 year ago) (1 children)

I'll stay away from the LLMs for now -- they're largely unhelpful anyway.

The value of those elements needs to be concatenated and displayed to the user. Is that right?

Right. The other components with a single text box seem to work fine, it's the multiple boxes in the phone component, and it's local state, that are confusing me to no end.

I think what you're talking about are Signals from Preact?

Oh, no, when I was talking to Bing it said that the local state interferes with the parent state, so I instead need to bring the parent state into the child. It sort of makes sense? At least the part that local and parent state can interfere with each other makes sense.

If you're still interested we could try writing a couple of basic components that get us part of the way there.

Please, I'm all ears. I have a feeling that your approach will help me a lot.

[–] otl@lemmy.sdf.org 2 points 1 year ago* (last edited 1 year ago) (1 children)

Ok! Just so I'm clear on what we need to do, what do you think the final HTML would look like? Happy to keep comms over Lemmy but email might be easier than fighting with Lemmy's markdown renderer. My deets are at http://www.olowe.co/about.html in "Contact"

[–] Decide@programming.dev 1 points 1 year ago* (last edited 1 year ago)

For sure, I'll send you an email.

edit: sent. Thank you again for the help.