Does the antd select component give a secondary confirmation prompt when the value changes? - ant-design-vue

When some important data is changed, such as the value of the selectA component is modified, the value of the component B will change, and there is a linkage relationship. Now, when the value of the selectA component changes, a second confirmation prompt box needs to be given, and click the prompt box the OK button, the value of selectA changes, otherwise it does not change.
I looked at the api of the select component and didn't find the hook before the value changed, how to solve this problem?

Make the select a controlled component that will only change if you change its value. E.g:
state = {
select: ""
}
handleChange = value => {
setSelect(value) // If you don't write this, the value of select will not change.
}
<Select value={select} onChange={handleChange} />

Related

Solution to Failure to Obtain an Input Value

When I entered a value in the input box and submitted it, the mandatory item verification failed, and the system displayed a message indicating that a parameter was empty and instructed me to enter a value. The code for obtaining the input value is as follows:
(see the solution in column C)
can you give me some advice about it?
The possible cause is that the method for obtaining the value is incorrect. As a result, the value in the input box cannot be obtained.
Use the onchange event to assign a value to the model and obtain the value of the input box. The method is as follows:
Initialize the model.
data:{
accountValue:''
}
Bind an event to the input box.
<input #change="getAccountValue" value="{{accountValue}}"></input>
Assign a value.
getAccountValue: function(e) {
this.accountValue = e.value // Here, e.value instead of e.target.attr.value is used.
}
Refer to the official document instead of generating a JavaScript object for coding. A JavaScript object may lead to compatibility issues.
Currently, the data binding mode of the quick app is unidirectional.
The value entered in the input box does not change the value of accountValue in data.
If the value of the input box is changed by setting this.accountValue to xxx, the onchange event of the input will not be triggered.
In this.accountValue = xxx format, if the value of accountValue before and after the change is the same, the page will not be re-rendered.

Tracking changes in textbox in scala js

I've a text box in my html file and I want to detect whenever a user changes the value of it and determine its updated value also. html code for text box is :
<input type="text" name="amount" id="amount" value="0" onchange="Demo().change(id,value)">
and in my scala file, I've implemented a function 'change' as :
#JSExport
def change(id:String):Unit={
appendPar(document.body,"Text Box value is changed and the new value is : "+document.getElementById(id).getAttribute("value"))
}
But it is not working in my case. What am I doing wrong here ?
Any suggestions ?
UPDATE : It is firing the event only when I press enter after altering the value in text box. Further, it is showing updated value as "0". How can I make it fetch from the text box instead of my pre defined value ?
You can use input event instead of change if you can ignore IE<=9.
The DOM input event is fired synchronously when the value of an or element is changed
From MDN.
Note that for non-text/textarea inputs (e.g. checkboxes, radio buttons, etc.) there are additional browser compatibility caveats, but you can just use change event on those. See http://caniuse.com/#search=input for details.
I also don't see where the variable id is coming from in your code. You should pass the string "amount" instead of id if that's what you want, like this: Demo().change("amount"). That would be quite unreusable, but it should at least work.
If you want the method to be more generic, note that javascript passes an Event object to all event handlers, and it has a target key which contains the HTML element on which the event happened (in this case that would be your textarea). You can get then easily get the value of that target.
If this is confusing, I suggest you try to implement this in JS first, and then translate this into Scala. You don't want to be fighting on both fronts at the same time.
You'll need to use one of the onkey handlers. For example:
Note that IIRC, this will also trigger if the user moves around with the arrow keys. So if you really want to only be called if it changes, you'll need to introduce a variable and check:
var lastValue: String = ""
#JSExport
def change(id:String): Unit = {
val newValue = document.getElementById(id).getAttribute("value")
if (lastValue != newValue) {
appendPar(document.body,
"Text Box value is changed and the new value is : " + newValue)
lastValue = newValue
}
}

Setvalue of autocomplete field doesn't work

I want to set value of autocomplete field using xf:setvalue. I know that firstly I have to set value of field and then set label (#label). I try to do that in following way:
<xf:setvalue ref="xxf:instance('fr-form-instance')//*[name() = $autocomplete-name]" value="'myValue'"/>
<xf:setvalue ref="xxf:instance('fr-form-instance')//*[name() = $autocomplete-name]/#label" value="'labelValue'"/>
After that in form builder I see, that in main instance it looks properly:
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all">
<form>
<section-5>
<control-10 label="labelValue">myValue</control-10>
</section-5>
</form>
</xf:instance>
but unfortunately in my autocomplete field there is no change. I can notice the change only if I go to 'edit source' button in form builder, and without any change, I click 'apply'. Then autocomplete is automatically refreshed and I see my label: 'labelValue'. What should I do, to refresh autocomplete field after setvalue ??
regards
You need to do this by setting the label of the autocomplete, not its value, which is done by dispatching the fr-set-label event to the autocomplete control. Then, internally, the autocomplete will do something very similar to what it does if the user had entered that label, in particular calling the service to retrieve the corresponding value.

Symfony2 DOMCrawler - How to select second option of a select tag

I'm trying to select the second option in a <select> tag with the DOMCcrawler. First of all, I select the second form in the page:
$form = $DOMCrawler->filter('form')->eq(1)->filter('input[type=submit]')->form();
Then I could change each value of the form by:
$form['value'] = "new value";
but I don't have a fixed key for each value. Instead, I have a variable number. E.g. I could have something like:
$form[1234];
but also could be
$form[4321];
depending on other variables. So I need to change the form values without knowing the key values, but its position in the node <form>. E.g. something like $form->firstKey();
Also, I want to select the second option inside <select> tag, not a fixed value. Any ideas on how to achieve it?

Getting "Change" event for a text field whose contents is changed by jQuery

I've made some pretty checkboxes using some pretty simple jQuery
HTML
<span class="iconElement checkBox" id="update_Check"></span>
<input type="text" id="update" name="update" value="0" class="hidden savedData" />
JS
$('.checkBox').live('click', function (e) {
if ($(this).hasClass('disabled') != true) {
$(this).toggleClass('checked')
var thisValue = parseInt($(this).next().val());
var newValue = (thisValue - 1) * (-1); // enusures the output is either 1 or 0, [ (1-1)*-1=0 and (0-1)*-1 =1 ]
$(this).next().val(newValue);
};
});
This is simply a span with a nice CSS background sprite, which when clicked changes toggles it's "checked" class, adjusting the CSS sprite from a "Tick" to an empty box. At the same time it also changes the content of a text field (hidden by CSS class 'hidden') to a 1 or a 0 to indicate whether the box is checked.
It has to have this 1 or 0 as when the data is passed to the next stage I have to have a value, an unchecked checkbox sends no value.
This all works fine!
BUT... I also need to be able to detect the "change" event of the hidden text field.
This is to be controlled by the "savedData" class.
$('.savedData').live('change', function () {
// do stuff now we know this has been changed
});
I could of course include this within the "click" event in the code above, but that's not practical for the application.
It seems that the "change" even is only trigger by elements which are changed by the keyboard or mouse, anything changed by jQuery is not being flagged.
Initially I was using hidden input type and thought that was the issue, but have changed them all to text type now and the problem is still there!
Any tips?!
It seems that the "change" even is only trigger by elements which are changed by the keyboard or mouse, anything changed by jQuery is not being flagged.
Yes, that is correct. That is precisely how this works. Only changes made by the user trigger event handlers: programmatic changes do not. The only way to trigger them is to do so yourself:
$(this).next().val(newValue).change();
The .change() triggers a change event on the element, so the handler will be called.