Giter Site home page Giter Site logo

Comments (52)

njuro avatar njuro commented on June 20, 2024 8

True, here it is https://codesandbox.io/s/dazzling-napier-ne3e6 do whatever you want with it, I don't have experience publishing npm packages :) So far it contains wrappers for TextInput, Select, Checkbox, Button and Form itself

from input.

raymond-ong avatar raymond-ong commented on June 20, 2024 3

I think I am encountering the same issue with Semantic UI Dropdown.
Also, notice from @njuro 's CSB, you need to click the checkbox 2 times for it to get ticked.
For the Dropdown case, nothing happens the first time the user selects something. Only the second attempt selects something from the Dropdown.
Regardless, I'm getting "undefined" inside the submit function.
Please advice. Thank you!

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024 3

thanks @JeromeDeLeon why not use onChangeEvent ? there is an example in readme for react native.

from input.

njuro avatar njuro commented on June 20, 2024 3

@JeromeDeLeon @bluebill1049 Thanks for the hints guys, I think I figured it out: https://codesandbox.io/s/dazzling-napier-ne3e6

@raymond-ong hope it will solve your issue too

from input.

njuro avatar njuro commented on June 20, 2024 2

Thanks @JeromeDeLeon now it works perfectly. I already created a little library in my project which wraps Semantic UI form components in RHFInput so I can work with it seamlessly, might publish it as a package once I polish it.

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024 2

closing this issue for now :) we can keep the conversation in here :)

from input.

njuro avatar njuro commented on June 20, 2024 2

@bluebill1049 yes I added it here https://codesandbox.io/s/dazzling-napier-ne3e6 see form/FileInput.js

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024 1

Can you generate a codesandbox for this one? Thanks.

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024 1

Thanks I will investigate the issue soon, in the meantime you could leverage custom register at useffect. React hook from input just some sugar syntax on top. Oh and please provide a codesandbox if u can.

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024 1

I think the problem lies in how we get the value from onChange and onBlur event because SUI passes the value to second param onChange(e, props) like so that's why data is always undefined because it only checked the e where the value is in the second param or maybe we can move that in state. Plus, invalid prop "value"... is showing when passing value that doesn't conform to their types (string or number).

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024 1

@njuro and @raymond-ong , I'l try to provide an example for this and let you know guys.

from input.

raymond-ong avatar raymond-ong commented on June 20, 2024 1

@JeromeDeLeon @bluebill1049 Thanks for the hints guys, I think I figured it out: https://codesandbox.io/s/dazzling-napier-ne3e6

@raymond-ong hope it will solve your issue too

Thanks @njuro for the codesandbox and @bluebill1049 for the onChangeEvent suggestion!
Will give it a try tomorrow :-)

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024 1

Might as well share it here :)

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024 1

that's awesome @njuro share the lib in here, we can publish it in our docs website.

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024 1

@bluebill1049 Sorry, I had the following misconception: inputs with a type of file can be controlled, which was cleared by the reactjs docs.

In React, an <input type="file" /> is always an uncontrolled component because its value can only be set by a user, and not programmatically.

I was trying to solve a problem the wrong way. I just used a hidden input (<input type="hidden" {...} />) and that was it 😁

Thank you for this great library and for the quick response! Have a good weekend!

no worries at all 👍 glad it's working out. you have a great weekend too.

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

@njuro are you using the latest version?

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024

I replicated your issue and led me to react-hook-form using my build though.

from input.

njuro avatar njuro commented on June 20, 2024

Here is the CSB: https://codesandbox.io/s/suspicious-frog-75c77

RHF is aware of the fields, but they are always undefined.

Looks like react-hook-form-input version 1.1.5 solved the error thrown by checkbox, but the value is still not there

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024

I can think of two solutions (maybe @bluebill1049 has better idea):

  1. Lift the state up and let the user pass the data:
// outside RHFI component
const handleChange = (e, { checked }) => {
  return checked;
}

// inside RHFI component
const handleChange = async (...args) => {
  // onChange here is the prop to lift
  const data = await onChange(args);
  setValue(name, data, isOnChange);

  // we can remove this
  if (onChange) {
    onChange(e);
  }
};
  1. We accept second param to accomodate SUI like what @bluebill1049 did in react-select
const handleChange = (e, props) => {
  const data = commonTask(e && e.target ? e.target : isSUI ? props : e);
  setValue(name, data, isOnChange);
  if (onChange) {
    onChange(e);
  }
};

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024

Oh! Thanks! @bluebill1049 I forgot that one.

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024

Can we not make it asynchronous?

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

Can we not make it asynchronous?

what do you mean?

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024

await event(args) something like this?

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

hmm then you need async right?

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

and it will always return promise and resolve

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024

Yes we can await that one.

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024

Anyway this is beyond the scope of the issue. we'll move this discussion in the spectrum.

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

sounds good

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

awesome @njuro! that's what i referred above.

from input.

njuro avatar njuro commented on June 20, 2024

Thanks @bluebill1049 , the last thing that annoys me is the
Warning: Failed prop type: Invalid prop 'value' supplied to 'Checkbox', which shows when the page is loaded, but does not seem to affect functionality.

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

we should fix it, do you have a codesandbox for it? let's patch it.

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024

@njuro , I mentioned that case above. Sorry, I wasn't able to follow up the example.

from input.

JeromeDeLeon avatar JeromeDeLeon commented on June 20, 2024

@njuro You can solve it by passing value as string like tos or isTos

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

@raymond-ong no worries 👍 guys

from input.

njuro avatar njuro commented on June 20, 2024

I added TextArea component to the CSB, but I am having a hard time figuring out how to preserver the value of uploaded file - see FileInput component. Any ideas @JeromeDeLeon @bluebill1049 ?

from input.

njuro avatar njuro commented on June 20, 2024

I investigated: I can cache the event in onChangeEvent method just fine and then log it:

function handleChange([event]) {
    const file = event.target.files[0];
    console.log(file);
}

But as soon as I try to return {value: file} or setValue(name, file) I get InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable

I made temporary workaround by passing a callback to FileInput which will store the uploaded file in parent component's state but that is not optimal. Can you think of something? Thanks.

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

do you have a codesandbox for this?

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

hey @njuro, after some investigation: you will need to use onChangeEvent for input file.

from input.

njuro avatar njuro commented on June 20, 2024

@bluebill1049 thanks, can you provide an example please? I am already using onChangeEvent in my codesandbox, but it generates said error

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

oh that's right @njuro i will do it today :)

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

use this :)

function handleChange([event]) {
    return {
      value: event.target.value
    };
  }

from input.

njuro avatar njuro commented on June 20, 2024

@bluebill1049 event.target.value contains only path/filename e.g. C:/fakepath/image.jpg, not the file content itself

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

what about e.target.files?

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

do you have reference on how semantic UI does it for onChange with input file?

from input.

njuro avatar njuro commented on June 20, 2024

I have no problem accessing the File object through event.target.files as I demonstrated in that CSB, I can log it to console. The issue happens when I try to assign the File object to value property either through setValue or through return { value: file }

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

how does semantic UI handle onChange?

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

worse case you may have to

function handleChange([event]) {
   setValue() // you probably already doing that
    return {
      value: event.target.value
    };
  }

from input.

njuro avatar njuro commented on June 20, 2024

@bluebill1049 Yeah, that's probably the best approach now. Closing this, thanks for you effort :)

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

my pleasure :) @njuro 🙏

from input.

alexfertel avatar alexfertel commented on June 20, 2024

@bluebill1049 I have the same issue. Is there any way to solve this? I cannot use setValue in the onChange event of a raw input. I also tried onChageEvent with no luck.

from input.

bluebill1049 avatar bluebill1049 commented on June 20, 2024

@bluebill1049 I have the same issue. Is there any way to solve this? I cannot use setValue in the onChange event of a raw input. I also tried onChageEvent with no luck.

Could you please share a codesandbox? also why you probably should consider to use Controller as this component is no longer maintained.

from input.

alexfertel avatar alexfertel commented on June 20, 2024

@bluebill1049 Sorry, I had the following misconception: inputs with a type of file can be controlled, which was cleared by the reactjs docs.

In React, an <input type="file" /> is always an uncontrolled component because its value can only be set by a user, and not programmatically.

I was trying to solve a problem the wrong way. I just used a hidden input (<input type="hidden" {...} />) and that was it 😁

Thank you for this great library and for the quick response! Have a good weekend!

from input.

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.