Richfaces prohibit event by passing by user - events

I have a text box and value change listener on it. And there is a save button. The user avoids/bypasses value change listener by directly editing text box value in html code and then saves it. How can i prohibit the user, so that he/she is not able to change value this way? And thus make sure that value change listener is always called.
I am looking for some generic mechanism to stop such cases on all inputs/and event listeners.
Thanks

You need to accept that the user can actually do EVERYTHING he wants with his client (the browser). He can disable Javascript, remove inputs completely, change validation or call Ajax functionality manually. He might not even use a browser and send an HTTP request using a command line tool.
It is just impossible to prohibit such things.
On the other hand I think that in case you use a valueChangeListener on your h:inputText, then it should be called in any case, because it will be evaluated serverside. It might be that you edited it the wrong way and the value actually doesn't change when you save the content of the form. (Check that the value really gets set by adding a breakpoint to your setter).
If you use Ajax functionality using <f:ajax> with event="change" and a listener, then there is no way to prevent bypassing it by manually editing the html. Either check for the changed value in your save method, or use the valueChangeListener instead.

Related

How to validate Acrobat fields before page is closed

I need to ensure that 2 fields in my pdf are consistent. They get filled in at different times, so I can't use field validation. I need to validate them before the page is closed.
I tried the page/close event but it's too late because the page closes without looking at the rc.
You might use both, the Leave Page event, as well as the Document Will Close event. In both cases, you will have to manually evaluate the field's values, and go back to the page itself.

Can you programmatically mark a validation observer as touched?

In my scenario I want to disable a save form button if the form has not been touched. I'm currently using v-slot="{ untouched }" on the validation-observer to achieve this. One of my checkboxes, however, is not wrapped in a validation provider. I.e., it's optional/not required. The problem is that whenever the checkbox value changes, my validation observer still has untouched set to true (assuming that's the only thing I've changed in the form). So I can't save my form even though I made a change to a boolean value. Is there a way where I can set my validation observer to istouched = true when my checkbox is changed? Or perhaps I need to manually check controls that have been changed that are not wrapped in a validation-provider tag.
FYI I'm using vee-validate 3.0

Get value from autocomplete text field in ApEx

I want to create a dynamic action, that will set a value to an item on the page, when the value of another item (autocomplete text field) is set.
So the proccess goes like this:
Click on the autocomplete field
type some letters
choose one of the suggested values
I cannot find an event that will be executed when the selection of one of the suggested values happens. This way, I cannot see how I can read the value of the autocomplete field, once a suggested value is selected.
The change event doesn't fit my needs, it doesn't execute when one suggested value is selected.
I had the same problem, found this link: https://community.oracle.com/thread/2130716?tstart=0 and modified my dynamic action as follows to get the desired behaviour:
Event = Custom
Custom Event = result
From the link:
the problem seems to be the default behavior of the browser. When you
enter some text into the autocomplete and the list is displayed, the
focus is still in the text field. Also if you use the keyboard cursors
to pick an entry the focus will still be in the textfield. That's why
the change event of the textfield doesn't fire. It only fires if you
leave the field.
On the other side if you pick an entry with the mouse, the browser
will remove the focus from the text field for a moment (before the
JavaScript code puts the focus back), because you clicked outside of
the field. But that's enough so that the browser fires the change
event.
I had a look into documentation of the underlaying jQuery Autocomplete
widget
(http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/) and
there is actually an event called "result" which can be captures if an
entry is selected from the drop down list.
Try "Lose Focus" as event. It will trigger your dynamic action when you leave the autocomplete field, i.e. your curosr is moved to another field.
This probably depends on the APEX version you are using.
In case of 18.2, because the underlying component is based on Oracle JET's "inputSearch" component, you need to use following configure to capture the select change event for text with autocomplete:
event: Custom
custom event: ojupdate
Reference:
https://docs.oracle.com/cd/E87657_01/jet/reference-jet/oj.ojInputSearch.html#event:optionChange
I turned on the browser console, then turned ApEx Developer toolbar debug, and found that, on the contrary, the "Change" event does fire upon user clicking with the mouse on one of the selections. However if the user uses keyboard (type a few letters to narrow the list down, then use down arrow key to arrive at desired value, then press enter) then the Change event does not fire, just as you say.
Moreover: even when you do get the value sent back via mouse-click initiated Change event, the value isn't the autocomplete's complete and valid value, but instead the possibly partial and wrong-case value just as typed by the user. I.e., the the change event's submission of the value precedes the autocomplete's substitution.
The answer that #VincentDeelen gave is the best alternative that I can see, although it doesn't quite give that "instantantenous synchronicity" feel. You could maybe use the "Key Down" event, but be careful with that. You could get a really excessive amount of web and db traffic as each and every keystroke (including corrections) results in another firing of the dynamic action.
Testing environment: ApEx 4.2.3 with Chrome 33 as well as IE 9.
p.s. This might be worth a mention to the ApEx development team as well.
It's not really ideal, but you could use onfocus(). I'm looking for the same thing you are, I think, a custom event that fires when the selection of a suggested value happens. I haven't found it yet though and that is my work-around for now. It will run whatever function you've created for this initially with no value, but once the selection is made it will return focus and run the function again with the right value. Like I said, not ideal but it works.
Jeffrey Kemp is right. You can set it up through a dynamic action using the custom event, result. You can also register it on page load using document.getElementById("{id}").addEventListener("result", {function}); or $("#{id}").result( function( event, data, formatted ) { //something here });.
Oracle apex 19 now added a "component event" when you create a dynamic action called "Update [Text Field with autocomplete]" - this action is fired when you select a value from the list, but not when you leave the field (similar to adding the custom event "ojupdate").

Listen to field changes inside a form in dojo

When saving a form I deactivate the save button to avoid double submission. Save happens through an Ajax call, so I stay on the same page. I want to re-enable the button only if the form got changed. How can I listen to any field change inside a specific form using Dojo 1.6 dojo.connect?
Look at line 358 of dijit/form/_FormMixin.js the connectChildren function :)
It gives you all the necessary information!
Basically if your children are connected (you could call the function to make sure), you then just have to monitor the form.value

jQuery, AjaxForm and success option

I'm using the jQuery Form plugin and more specifically the ajaxForm method to hijack a normal form and post it using ajax. I have a form with lots of rows. Each row has edit and delete options and each section has an add option. Hijacking the form I can work out on the server whether to add, edit or delete but would like the ability to know which button was pressed in the success method back in my JS. Is this possible?
I know there are two params: responseText and statusText and that I can work out the button type in beforeSubmit but I need it when the data is returned which button has been pressed. The reason is that I want to display a form in a light box for edit and add but for delete I want to do something different. It seems a bit naff to check the data coming back to look for a certain string (not to mention flakey and unmaintainable).
Anyone know of a simple solution?
Look at the beforeSubmit option: it's a function that will get called, well, before submit. More importantly, it provides the data. You could look at the data and set a flag that would then be used within the success function. This isn't beautiful, but better than being coupled to the server's behavior.
In this situation, I have often just created two different forms-- one for update and one for delete. Then, instrument them separately.

Resources