I have a button that when clicked uses the text entered in a nearby text field in a script that is within the click rule of the button. Just wanting to know the best way to use the keycode 13 (return key) after the text is entered in the text field so that it can force the click rule to run on the button, and therefore having the effect of clicking the button. So basically, when the person enters the text in the text field, they press return/enter and the code within a nearby buttons click rule runs. Could the code perhaps be placed within a business rule? then when the button is clicked or the enter key is pressed after entering text in the text field it runs the business rule?
Hi Don, Before I get started, I want to let you know that triggering events/scripts when the 'enter' key is hit in a field is not supported using the standard Composer API. To achieve this result we will fall back to JQuery, which limits the support for this functionality to HTML only. The following is one possible way of achieving your desired functionality, it has not been implemented in a production environment and would require a full round of testing before release to ensure compatibility with the browsers and devices supported by Composer forms. The steps are as follows:
Add a text field, button, and 2 general purpose business rules to your form.
Add the following code, or equivalent to the button's click script:
sfc.fireEvent('evtSomeEvent', me, null);
Note: this script will trigger an event when the button is clicked, you should rename evtSomeEvent to something more appropriate. The first business rule will bind a function to the text field so that it will also fire the same event when the 'enter' key is pressed.
Edit the first business rule
Navigate to Rules > Business > Business Rule and set the value to 'Script Based'
Replace {HitEnter}with a Static, Node reference to the text field
Save the script and business rule
Next, edit the second business rule
Note: The second rule is the event handler, it will run the code that should be triggered when either the 'enter' key is pressed or the button is clicked.
As with the first business rule, set it to script based and edit the script
Navigate to the 'Triggering Conditions' tab
Update the triggering conditions, so that the rule doesn't run on initialise, and does run when your custom event is fired
Finally, write the script that you want to have run when the event is fired, in the 'Script' tab of the business rule.
Thanks Jye, I put in everything as above. The click button console.logs the value of the text field every time no problem,when i try pressing 'enter' after typing some text, console.log returns an empty string. on a second attempt it returns the correct value. but If I change the value and press 'enter 'it logs out the old value, it doesn't change to the new one perhaps I can demonstrate this to you on your next visit.
HI,
I have a button that when clicked uses the text entered in a nearby text field in a script that is within the click rule of the button.
Just wanting to know the best way to use the keycode 13 (return key) after the text is entered in the text field so that it can force the click rule to run on the button, and therefore having the effect of clicking the button.
So basically, when the person enters the text in the text field, they press return/enter and the code within a nearby buttons click rule runs.
Could the code perhaps be placed within a business rule? then when the button is clicked or the enter key is pressed after entering text in the text field it runs the business rule?
Don
Attachments to support comments below:
Widgets.png
Enter Node Reference.png
Enter Node Reference - Script.png
Handler.png
Script.png
Before I get started, I want to let you know that triggering events/scripts when the 'enter' key is hit in a field is not supported using the standard Composer API. To achieve this result we will fall back to JQuery, which limits the support for this functionality to HTML only.
The following is one possible way of achieving your desired functionality, it has not been implemented in a production environment and would require a full round of testing before release to ensure compatibility with the browsers and devices supported by Composer forms.
The steps are as follows:
Note: this script will trigger an event when the button is clicked, you should rename evtSomeEvent to something more appropriate.
The first business rule will bind a function to the text field so that it will also fire the same event when the 'enter' key is pressed.
Note: The second rule is the event handler, it will run the code that should be triggered when either the 'enter' key is pressed or the button is clicked.
I put in everything as above.
The click button console.logs the value of the text field every time no problem,when i try pressing 'enter' after typing some text, console.log returns an empty string. on a second attempt it returns the correct value. but If I change the value and press 'enter 'it logs out the old value, it doesn't change to the new one
perhaps I can demonstrate this to you on your next visit.
Don