dynamic alert message

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

dynamic alert message

mabu
Hi,

is it possible to specify a dynamic alert message for a control?

My simple workflow is as follows:
1. On button click a submission is triggered
2. Depending on the submission result I enable a constraint and set the dynamic alert value in the resource instance.

The first time, it works like a charm. If I trigger the button a second time (the constraint is already enabled), the alert value shown under the input control is updated but the error summary is not.

Can you please give me a hint?

Martin
Reply | Threaded
Open this post in threaded view
|

Re: dynamic alert message

Alessandro  Vernet
Administrator
Hi Martin,

Is this in XForms you wrote by hand, or are you using Form Builder (I imagine it is the latter since you're referring to the error summary)? What is the button you are talking about? How do you enable the constraint upon submission result? And most importantly, would you be able to create and share with us an example that reproduces the problem, so we can debut this here?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: dynamic alert message

mabu
Hi Alex,

the xforms code is written by hand because it is inside a xbl component. Here is a simple example without a submission but resulting in the same problem.

Test workflow:
1. Enter value in input field
2. Press 'Test1' button
3. Validation Message 'error code 1' is shown
4. Press 'Test2' button
5. Validation Message 'error code 2' is shown under the input field, but not in the error summary

Martin
Reply | Threaded
Open this post in threaded view
|

Re: dynamic alert message

Alessandro  Vernet
Administrator
Hi Martin,

Sorry for the late response. After reading your message, I checked how the error summary was getting its values, and found a little issue, which got me into some rabbit holes (https://github.com/orbeon/orbeon-forms/issues/2505).

Getting back to the topic at hand, the issue is that the error summary stores the error message when the control becomes invalid, so and if the alert changes after the control became invalid, the error summary has no way to know.

This situation also happens in Form Runner if you switch language. In that case, a `fr-update-lang` is dispatched to the error summary (see below). So you could do the same in your code: after the resource changes, explicitly dispatch that event to the error summary.

https://github.com/orbeon/orbeon-forms/blob/tag-release-4.10.2-ce/src/resources/apps/fr/components/components.xsl#L267

You'll let us know if this works for you.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: dynamic alert message

mabu
Hi Alex,

I updated my simple example test.xml.
Now I have following behaviour: The first time I press button "Test 2" the problem still exists. If I press the button a second time the errory summary is updated.
I also tried another option. If I dispatch the event using an additional button "Test3" then it works the first time!?

Martin
Reply | Threaded
Open this post in threaded view
|

Re: dynamic alert message

Alessandro  Vernet
Administrator
Martin, thank you for sharing the source of an example. I am not sure what the issue could be, off the top of my head, and will need to debug this with the example you provided. I'll follow-up here once I got a chance to do so.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: dynamic alert message

Alessandro  Vernet
Administrator
Hi Martin,

First just a note, somewhat off-topic: when you have multiple actions, e.g. xf:setvalue running on event="DOMActivate", instead of putting event="DOMActivate" on each one of them, you can nest them into an <xf:action event="DOMActivate">. This avoids repetition, and more importantly, I think, makes the code clearer.

You make the input required and valid if either /form/valid or /form/skip-valid/evaluation are true, and you have a custom alert in case that last rule fails.

Now, if I put a value in the field, and click on the first button, since it sets both valid and skip-valid-evaluation to false, I imagine you'd want your custom message ("error code 1") to show, which is what happens.

After this, if I click on the second button, you'd like "error code 2" to show right away, but instead I have to click twice on the button.

The thing is that when the error summary gets the fr-update-lang, it reads the alert for the control with xxf:alert(), but that alert hasn't be recalculated yet, as this is done  during the refresh phase. To make this work, you can force a refresh before dispatching the fr-update-lang to the error summary:

https://gist.github.com/avernet/751767a7cc6a6da3becf

Yes, I know, this is a  bit "subtle". Ideally we would have a better way for the error summary to know about errors than relying on events, which are non-declarative, and thus making code more complicated and error-prone.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: dynamic alert message

mabu
Hi Alex,

Thank you for clarifying. Now it works!

Martin
Reply | Threaded
Open this post in threaded view
|

Re: dynamic alert message

Alessandro  Vernet
Administrator
Martin, excellent, and thank you for confirming this.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet