Comments (52)
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.
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.
thanks @JeromeDeLeon why not use onChangeEvent
? there is an example in readme for react native.
from input.
@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.
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.
closing this issue for now :) we can keep the conversation in here :)
from input.
@bluebill1049 yes I added it here https://codesandbox.io/s/dazzling-napier-ne3e6 see form/FileInput.js
from input.
Can you generate a codesandbox for this one? Thanks.
from input.
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.
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.
@njuro and @raymond-ong , I'l try to provide an example for this and let you know guys.
from input.
@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.
Might as well share it here :)
from input.
that's awesome @njuro share the lib in here, we can publish it in our docs website.
from input.
@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.
@njuro are you using the latest version?
from input.
I replicated your issue and led me to react-hook-form
using my build though.
from input.
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.
I can think of two solutions (maybe @bluebill1049 has better idea):
- 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);
}
};
- 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.
Oh! Thanks! @bluebill1049 I forgot that one.
from input.
Can we not make it asynchronous?
from input.
Can we not make it asynchronous?
what do you mean?
from input.
await event(args)
something like this?
from input.
hmm then you need async right?
from input.
and it will always return promise and resolve
from input.
Yes we can await that one.
from input.
Anyway this is beyond the scope of the issue. we'll move this discussion in the spectrum.
from input.
sounds good
from input.
awesome @njuro! that's what i referred above.
from input.
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.
we should fix it, do you have a codesandbox for it? let's patch it.
from input.
@njuro , I mentioned that case above. Sorry, I wasn't able to follow up the example.
from input.
@njuro You can solve it by passing value
as string like tos
or isTos
from input.
@raymond-ong no worries 👍 guys
from input.
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.
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.
do you have a codesandbox for this?
from input.
hey @njuro, after some investigation: you will need to use onChangeEvent
for input file.
from input.
@bluebill1049 thanks, can you provide an example please? I am already using onChangeEvent in my codesandbox, but it generates said error
from input.
oh that's right @njuro i will do it today :)
from input.
use this :)
function handleChange([event]) {
return {
value: event.target.value
};
}
from input.
@bluebill1049 event.target.value
contains only path/filename e.g. C:/fakepath/image.jpg
, not the file content itself
from input.
what about e.target.files
?
from input.
do you have reference on how semantic UI does it for onChange with input file?
from input.
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.
how does semantic UI handle onChange
?
from input.
worse case you may have to
function handleChange([event]) {
setValue() // you probably already doing that
return {
value: event.target.value
};
}
from input.
@bluebill1049 Yeah, that's probably the best approach now. Closing this, thanks for you effort :)
from input.
my pleasure :) @njuro 🙏
from input.
@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 I have the same issue. Is there any way to solve this? I cannot use
setValue
in theonChange
event of a raw input. I also triedonChageEvent
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.
@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)
- RHFInput `as` props shows errors in TypeScript HOT 5
- RHFInput 'onBlur' mode deselects selected option when using React-Select HOT 5
- Issues with RHFInput and validation HOT 1
- When value is set to select, I can no longer select another value
- Type error about async validate function HOT 3
- Warning: A component is changing an uncontrolled input of type text to be controlled. HOT 2
- RHFInput + AntD TimePicker isn't working after 1.1.0 HOT 1
- Using RFHInput with MaterialUI TextField : `[object HTMLInputElement]` when empty HOT 1
- Question: Proper way of using RHFInput in MaterialUI custom component? HOT 4
- Lost selected option in Select component when value is 0 HOT 4
- Checkbox validation is not working as expected HOT 10
- AntD switch is not correctly if type is checkbox. HOT 4
- React Semantic UI modal with React Hook Form default values disappear HOT 8
- RHFInput type issue with setValue HOT 4
- Why always get a strange number when using the V4 version in ReactNative HOT 1
- RHF Input with React-Select Libary HOT 2
- export 'useFormContext' was not found in 'react-hook-form' HOT 1
- RHFInput + Semantic UI (Checkbox and Select) HOT 1
- Cursor AutoFocus to the end on editing text HOT 1
- Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from input.