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}
...
I'm writing an edit function (plain javascript & HTML / Chrome / Windows 10).
The data is in localStorage as a series of records, just 2 records in the toy code mentioned below.
I want the user to specify the number of the record to edit, then the code should pre-fill the textarea field with the retrieved content of that record. I want to allow the user to make changes and then press a Store button to store it back in localStorage.
My problem is that when I prefill the input field, I see the record content briefly and then the input field clears. I've tried .value and .defaultValue
editField.value = localStorage.getItem('jnl' + locStoreNo).replace(/(.*?) `\d*?`/, "$1");
and
editField.defaultValue = localStorage.getItem('jnl' + locStoreNo).replace(/(.*?) `\d*?`/, "$1");
the result is the same. (The regex is to hide a sequence number)
The code is in a JSFiddle here: https://jsfiddle.net/roygrubb/zxedbfqr/2/
That performs more or less the same - it shows the value briefly - but then does something different: It goes to a 404. I don't understand this either ¯_(ツ)_/¯
What I'm trying to do seems so basic, that I think I must be missing something blindingly obvious.
What have I missed? Thanks!
Whenever you've got a <form> that you want to handle through JavaScript, you have to ensure that the default form submission action does not happen. If the <form> does not have an "action" attribute, the default is to reload the current page.
By default, a <button> element will be assumed to have "submit" as its type. To prevent form submission, therefore, the simplest thing to do is make the button have "button" as its type.
That may not be all you need to do, depending on the details of the form. It may be necessary (or simply a good defensive move) to have a handler for the "submit" event on the form to prevent the default action.
I have two input fields that had the user access card and password. and the user click on submit button to authenticate.
I'm using DTM in my app to capture the user navigation but I want also to get the values of those field to my DTM so I would know who the user is.
And here is what I tried but with no luck.
Created Data element as below:
And created Event based rule. But not sure how to get the values to be shown in my report:
Thanks for your help.
Example Form
Since you did not post what your form code looks like, here is a simple form based on what I see in the screenshots you posted, that I will use in my examples below.
<form id='someForm'>
User Name <input type='text' name='userName'><br>
Password <input type='password' name='userPass'><br>
<input type='submit' value='submit' />
</form>
Data Elements
Okay first, let's go over what you did wrong.
1) You said you want to capture two form fields, but you only have one data element...maybe? You didn't really convey this in your question. I just assumed as much because of what you did throughout the rest of the screenshots. But to be clear: you should have two separate data elements, one for each field.
2) The CSS Selector Chain value you used is just input, so it will select the first input field on the page, which may or may not coincide with one of the input fields you are looking to capture. So, you need to use a CSS selector that is unique to the input field you want to capture. Something as simple as input[name="userName"] will probably be good enough (but I cannot confirm this without seeing your site). You will need to do the same for the 2nd Data Element you create for the other input field (e.g. input[name="userPass"])
3) In the Get the value of dropdown, you chose "name". This means that if you have for example <input type='text' name='foo'>, it will return "foo". Since you want to capture the value the user inputs, you should select "value" from the dropdown.
Solution
Putting all the above together, you should have two Data Elements that look something like this (one for the user name field and one for the password field; only one shown below):
Event Base Rule
Okay first, let's go over what you did wrong.
1) The value you specified in Element Tag or Selector is input. You aren't submitting an input field; you are submitting a form. Input fields don't even have a submit event handler! Your Event Type is "submit", so at a minimum, Element Tag or Selector should be form. But really..
2) Ideally, you should use a CSS Selector that more directly and uniquely targets the form you want to trigger the rule for. For example, maybe the form has an id attribute you can target in your CSS Selector. Or maybe the form is on a specific page, so you can add additional conditions based on the URL. What combination of CSS Selector or other conditions you use to uniquely identify your form depends on how your site is setup. In my example form above, I added an id attribute, so I can use form#someForm as the CSS Selector.
3) You checked the Manually assign properties & attributes checkbox, and then added two Property = Value items. This tells DTM to only trigger the rule if the input has a name attribute with value of "userName" AND if it has a name attribute value of "userPass". Well name can't have two values at the same time, now can it!
<input name='foo' name='bar'> <!-- bad! -->
All of this needs to be removed, because again (from #1), you should be targeting a form, not an input field.
4) For good measure, looks like you added a Rule Condition of type Data > Custom, but the code box is empty. The rule will only trigger if the box returns a truthy value. Since there is no code in the box, it will return undefined (default value returned by a javascript function if nothing is returned), which is a falsey value. This also needs to be removed.
Solution
Putting all the above together, the Conditions section of the Event Based Rule should look something like this:
But again, ideally your conditions should be more complex, to more uniquely target your form.
Referencing the Data Elements
Lastly, you can reference the input fields to populate whatever fields in the various Tool sections with the %data_element% syntax. For example, you can populate a couple of Adobe Analytics eVars like this (data element names reflect the examples I created above):
Or, you can reference them with javascript syntax in a custom code box as e.g. _satellite.getVar('form_userName');
Additional Notes
1) I Strongly recommend you do not capture / track this type of info. Firstly, based on context clues in your post, it looks like this may count as Personally Identifiable Information (PII), which is protected under a number of laws, varying from country to country. Secondly, in general, it is a big security risk to capture this information and send it to Adobe (or anywhere else, really). Overall, capturing this sort of data is practically begging for fines, lawsuits, etc.
2) Note that (assuming all conditions met), the "submit" Event Type will track when the user clicks the submit button, which is not necessarily the same thing as the user successfully completing the form (filling out all the form fields with valid input, etc.). I don't know the full context/motive of your requirements, but in general, most people aim to only capture an event / data on successful form completion (and sometimes separately track form errors).
Problem is very simple. I am using certain API which is called when I click a button and some of the fields are being filled from a widget that I created
I use that widget at multiple places in my system
The problem is that when those fields are filled I need
#api.onchange('exmplple')
method to trigger them, but it doesn't (I would say it's a bug).
What would be the workaround or solution to trigger that method when those fields change whenever my widget works?
Update:
Sorry for the confusion that my question caused. I will try to explain what exactly I was thinking and why I only have tried server side things so far. The problem is that in any other situation python code api.onechange would work completely fine.
#api.onchange
def do_smth_when_country_changes(self):
if country_id = 133
self.lang = 'pl_PL'
elif:
.......more ifs
But I have fields which are filled from google maps (JavaScript code that I wrote).
<field name='autocomplete' widget='gmap_autocomplete' country_id='country_id'>
<field name='country_id'>
Here when i search for address with autocomplete field, and i click on one, country_id field will be filled with country. And Also there are some other field has to change value whenever country_id changes (for example res.partner field lang).
<field name='lang'/>
Since Python onchange method doesn't trigger country_id field I though that JavaScript would probably only thing that would solve my problem. So What I want to do is to access field coutry_id in specific form view (let's say only in view_partner_form) and when it changes access value of lag field and change it as well.
I am pretty new to oracle apex and working on a case for myself to get oracle apex 5 more in control... :-).... hopefully. I have 2 pages: 1 interactive report on a table and 1 for a form to add and modify
records. In the form there are 4 fields: P12_VAT_PERC, P12_VAT_AMOUNT, P12_NET_AMOUNT and P12_TOT_AMOUNT (all 4 database fields, type number). I have created one dynamic action on event lose focus on one of the 4 field items mentioned above. The event is fired when true with 2 actions. Action 1 is set value on P12_VAT_AMOUNT, set type javascript expression:
($v('P12_VAT_PERC') / 100) * $v('P12_NET_AMOUNT');
Action 2 set value on P12_TOT_AMOUNT, set type javascript expression:
parseFloat($v('P12_NET_AMOUNT'))+parseFloat(($v('P12_VAT_PERC') / 100) * $v('P12_NET_AMOUNT'));
In the form it works. Values for P12_VAT_AMOUNT and P12_TOT_AMOUNT are calculated and displayed correctly as number (with the decimals if applicable) once calculated after losing focus on one of the 4 fields. But when page is submitted the value is not displayed correctly in the report and also not correct stored in database. I.e. before submitting P12_VAT_AMOUNT is calculated and displayed as 25.919999999999998. After submitting in the report it is displayed as 25919999999999998. I am missing the decimal sign. Also in the database it is stored like 2.592E16.
When I open this record in the form again for editing, it is initially displayed as in the report like 25919999999999998. When changing i.e. P12_VAT_PERC and change the focus, the field is caclulated correctly and displayed again with decimal sign on correct place. After submit it goes wrong again. To solve this, I found out that having the dynamic action also fired on page load (I enabled this option), this part of the problem was solved. Values are displayed correctly in form by javascript, but the wrong value seems to be stored in the database and not correctly displayed in the interactive report.
Same behavior for P12_TOT_AMOUNT.
I have the idea that APEX is using the dot as decimal character but the regional settings (Dutch) of the machine on which the browser is running are set to comma. When I enter a comma as decimal sign, the calculated fields are showing as NaN.
What do i do wrong? Hope someone can help me and put me in de direction where to find the solution.
The real problem that javascript is using always a dot as decimal separator and my locale is set to decimal. I will now focus on that problem. It has nothing to do with Apex.