Clearing a text field value using a final-form calculator - javascript

I am trying to use the final-form calculator to clear a field whenever another field has changed.
In my example, I have two fields. Whenever the first field changes, the second field is cleared. This is expected.
However, A problem arises when the parent component of the form is re-rendered. Each time the parent component calls to it's render function, the second field is cleared even though the first field has not changed. This can be observed by clicking the forceUpdate button at the top.
Is it possible to prevent the second field from clearing like this? Preferably without using shouldComponentUpdate

I have been able to resolve it by moving the decorators array outside of the component.
const decorators = [calculator]; // declared outside of App
And reference the value in the form props
<Form
decorators={decorators}
...

Related

Why does the object synchronize(reactive) outside component whereas the single variable does not?

To demonstrate this issue, I've created the same behavior via JSFiddle.
Check this out https://jsfiddle.net/sarapmax/xy5qg6bo/21/
As you can see, when I click the submit button, it emits the values out to the parent component.
Then, I declared the empty parentBudget object in the parent component and set it equal to the emitted values.
The thing is when I click the submit button and type on those v-model inputs in the child, they are syncing with the parent. But this.foo which is not outside this.budget object is not syncing with the parent.
My question is why? Ideally, I don't want the parent synching with the child every time I type, it should perform only when I press the submit button.

How do I detect in my class component which input value's clicked in functional component?

How do I detect in my class component which <input/>'s value was clicked in my functional component? For example, if the user clicks Yes, then I want the postIsClicked() (which's in my class component) function to display that it's indeed detected the Yes that's been clicked.
My attempt consisted of giving a name to the inputs and then trying to detect is via e.target.name but it just keeps loggin No has been clicked in the console regardless of which button I press (Yes or No)
What am I doing wrong?
Pastebin below.
https://pastebin.com/tWNM16p3
The onClick function can receive the event as argument, so you can access the value by getting e.target.value.
In your case you just need to receive event as argument to postIsClicked(event) and then console.log("clicked" + event.target.value)

VueJS <input> value change not calling #change

With VueJS, I have two seperate components.
A modal and a form.
In the modal form, the user inputs a PIN that gets confirmed then this value is set to an input tag in the form to basically save this value.
In the modal component, I set the value simply like this:
document.getElementById('pin').value = this.pin_input;
Within the form component, the input tag is like this:
<input type="hidden" #change="submit()" id="pin">
In the console, the value of this input tag get's set correctly, though the #change="submit()" is not getting called when the values changes.
submit method code within form component that is not getting called:
methods : {
submit : function(){
console.log("SUBMIT HERE");
}
}
Why is my input tag's #change not getting called?
Setting the value on a DOM element does not fire the input / change events. This is why the event listener you set in vue is not called.
You can fire those events manually, they will then be picked up by vue.
var element = document.getElementById('pin');
element.value = this.pin_input;
// Works in most modern browsers.
var event = new Event('change');
element.dispatchEvent(event);
From my point of view, For communication between components it's better to use:
some state management like Vues https://vuex.vuejs.org/, and save input value in separate store
or
try with custom methods https://v2.vuejs.org/v2/guide/components-custom-events.html
use parent component and pass callback into child components.
#change will not work in your case

cannot update existing input compoent value in ReactJS

I have a project that has a list of stuffs using ReactJS, please see JSBIN, and want to search these stuffs with keyword.
TEST: input mi in search box to search ID, the this.state.data is filtered right but input value don't update right(gary should not appear).
I've checked the problem is input component
<input type="text" defaultValue={this.props.data.userid} ref="userid" disabled name="userid" />
with defaultValue for the fist time render, but upcoming render don't change it's value again; But if changed it to value, it's cannot be edited
Question: how to make search right also make all input editable with minimum code modify?
Your JSBin gives me strange output (and in a language I do not understand).
However, it looks like your problem is inside handleChange(), which is inside your Forms component. If you want the content of the page to update, there should be a this.setState function somewhere inside handleChange. In current setup, handleChange() only does console.log, but does not re-render..

Making meteor rerender "unchanged" fields

The (simplified) template below renders a form with two input fields, pre-filled based on the data context. The form can be opened for several different data contexts (though only one at a time), in which case I want all fields to be rerendered with the new data - which mostly happens.
<template name="form">
<input type="text" value="{{title}}">
<input type="text" value="{{start_value}}">
</template>
The problem arises when two data contexts have the same value for either field - e.g. it is very common for start_value to be 0. In this case, the corresponding input field will not be rerendered when the data context switches. Perhaps an example is in order:
User opens form for a data context with start_value = 0
User changes the input field corresponding to start_value from 0 to 12
User closes the form without saving
User opens form for another data context with start_value = 0
The field corresponding to start_value still says 12
This seems to happen for all (primitive) identical values. Using a helper to return the value changes nothing but does confirm that the helper is rerunning as expected.
I can work around this with an autorun-afterflush on the template instance to explicitly update the input fields, but is there a more idiomatic way to make Meteor rerender "unchanged" fields?
Edit:
Here is working example (and by working I mean it shows what doesn't work).
Just create those two files in the client directory of a clean Meteor project and you should be able to observe the behavior. Items 1 and 2 have the save value and so the second input field will not change when you switch between them even if you have altered it manually. Items 3 and 4 have the same title and exhibit similar behavior.
I'm not exactly sure if I'm answering your question but if your trying to clear a value after the user closes the form so it does not repopulate with that value on reopen, then you could use the onDestroyed function
to do any clean up you need, such as clearing a session which appears to be what you set when the form is opened.

Categories