How can I create my own validation rule in orbeon xforms? - orbeon

Here's the problem, I need to validate the form before submitting in the next way, before user can submit anything he should click "Save" button, if he tries to click "Submit" one receives message something like "You should save form before submit".
First I thought that I can add system field to the form like save-indicator, add constraint to like that
<xforms:bind id="isSaved-bind" nodeset="isSaved"
name="isSaved" type="xforms:string" constraint="number(.)=1" required="true()"/>
And add
<xforms:setvalue ref="xxforms:instance('fr-form-instance')/person/isSaved">1</xforms:setvalue>
to actions when "Save" button beeing clicked.
But, the problem is that I have to rewrite all existing forms to insert new code there.
Is there any posibility to make global variable like "isSaved" and check it for every form, before submit, and show error message if user didn't save form?
Or may be there another way that I can't see?
Will be appreciated for any answers.

Form Runner keeps track of whether the form is clean or dirty, and you can access that information in xxforms:instance('fr-persistence-instance')/data-status. The code handling the submit is in apps/fr/includes/persistence/persistence-model.xml. There you could change the listener for DOMActivate on fr-submit-button to read like:
<xforms:action ev:event="DOMActivate" ev:observer="fr-submit-button">
<xforms:action if="instance('fr-persistence-instance')/data-status = 'clean'">
<xforms:setvalue ref="instance('fr-persistence-instance')/submit-or-save-or-send">submit</xforms:setvalue>
<xforms:dispatch name="fr-save-action" target="fr-persistence-model">
<xxforms:context name="fr:check-data-valid" select="true()"/>
</xforms:dispatch>
</xforms:action>
<xforms:action if="instance('fr-persistence-instance')/data-status = 'dirty'">
<xforms:message>You must save form before submitting it.</xforms:message>
</xforms:action>
</xforms:action>
Note that persistence-model.xml is in orbeon-form-runner.jar. To change that file, extract it from there, and place it in the WEB-INF/resources/apps/fr/includes/persistence/persistence-model.xml. That version on WEB-INF/resources will take precedence over the one in the jar file. Also note that these type of changes that rely on the internals of Form Runner or Form Builder have a chance to break when upgrading to a new version of Orbeon Forms. So you might want to carefully keep track of them, so you can more easily reapply the changes when you upgrade.

I use a global flag indicator to check if the form is saved before closing the window or submit and it works pretty well.
This information is cleary explained in this wiki.
All the best!

Related

Form Dynamic Tag Manager

I'm trying to tracking this form https://secure-www.seat.com/content/lu/brand/fr/contact/arrange-a-test-drive.htx with Dynamic Tag Manager (DTM)of Adobe.
I've create a Rule Based Event like this:
Event Type --> Submit
Apply event handler directly... (In fact I try with check and uncheck)
Element Tag --> form
The same rule, with my personal page form is successful: http://pujoljulia.com/ (!Hablémos! link). As you can see I used form Tag selector, but also I tried other, button, div... and rule doesn't trigger ever.
However, in both pages the Click Map listener recognized event. Honestly I try all options and I can't see why. Can someone help me?
I'm trying to tracking this form
https://secure-www.seat.com/content/lu/brand/fr/contact/arrange-a-test-drive.htx
with Dynamic Tag Manager (DTM)of Adobe.
I took a look at your page and there it looks like DTM is not being loaded on that page. I could not find the _satellite object.
Dynamic form handlers on sites that have customized forms are fairly unstable, usually one or the other breaks. I did not look too deeply to the seat.com page, but it looks to me like JavaScript is used to override default behavior and this could be causing the problem. Clicks do get registered, but this would not solve your problems, as
What I would suggest is that you move the tracking to the next page, where the form has been submitted. This is far more reliable and has a lower chance of causing issues. Usually you can use URL parameters or page naming variables to target on these pages.

How can I manipulate a form / inputs to be ignored when a form is submitted

I'm using ExpressionEngine and SafeCracker along with Ajax (plugin: jquery.form.js - http://jquery.malsup.com/form/).
Best I can tell, SafeCracker will only allow for updating a single entry at a time. However, the UI / UX necessitates that a list be displayed. I've proof of concept'ed an entry by entry on-demand form. That is, click a particular edit link next to each entry and a snippet of jquery creates a form along with displaying a submit button. Click submit and that single entry updates. The inputs don't exist until the Update link is clicked
What I would prefer to do, if possible, is to create the non-form and form versions of each entry as the page is renbered and use some sort of toggle to display one or the other. Again, doable. Then, when I click the Edit link I'd add the necessary attributes to the input so that entry's form elements will be read but the other (display: none) elements for the other entries will be ignored. I'm thinking (out loud) that if I add the attr("name", some-value) that would work. That is, an input with no name will be ignored.
Yes, I can test this and I will. However, even if it works I'm not sure if it's a best practice and/or there's a more ideal way of accomplishing my ends. I'm here looking for validation and/or additional expertise and input.
Thanks in advance.
Just set disabled property to inputs and they will excluded from Form submission, whatever input fields are hidden or visible. Different jQuery methods, like submit() and serialize() follow specification of HTML 4 and exclude all disabled controls of a forms. So one way is to set
$('your_input').prop('disabled', true);
or ,
$('your_input').attr('disabled', 'disabled');
Check following link:
http://www.w3.org/TR/html401/interact/forms.html#successful-controls
Also, you may use a general button instead of a submit, as result you can handle click event on it and within that event you can make exclusion, validation, manipulation on values and what ever you like.
You can put a disabled attribute on them server side or set the property via jQuery:
$(".hidden input").prop("disabled", true);

Orbeon: creating my own delete button

2/28: Seems the Go uri is only if you create your own persisten layer. I'm going to try and use a link on my form to do this. If I can figure out how to find the form_id of the current form.
Original Question:
I'm trying to restrict who can delete a form instance. It seems if people can get to the form-runner summary page, they can click the delete button and delete a form (even if they are not allowed to do any "/orbeon/fr/hr/expense-report/edit/*" options.
Anyone found a way around this issue. I wonder if we could use the GO button on the form /edit/ view to build our own delete feature.
If I look at the page source from the hr/expense-report/edit/f36b446c3ddbf7c63ec033d5c6fa7ce4 view, that the from does have the details to the actual form instance.
Example:
form id="xforms-form" class="xforms-form xforms-initially-hidden xforms-layout-nospan" action="/orbeon/fr/Test/Hidden_Search/edit/f36b446c3ddbf7c63ec033d5c6fa7ce4"
I wonder if that information could be passed to the "GO" button, if I have that on my page?
Right now, if users can access the Form Runner summary page, they can also access the "delete" button. Showing the "delete" button on the summary page for some users but not others, requires a change to Form Runner, which shouldn't very complicated.
For instance, if you only want the "delete" button to be shown for users with the role can-delete, on this xforms:bind of fr/summary/view.xhtml add the attribute:
relevant="xxforms:is-user-in-role('can-delete')"

Ruby on Rails registration data?

I am trying to build a registration page, with two steps.
The first step displays a form with name, email, pass.
The second step will display a ReCaptcha.
The problem is how do I store the form data and display a new form with a captcha?
I was thinking sessions, but I know you're not supposed to store sensitive information in sessions.
I was thinking of using Ajax to render the ReCaptcha if the name, email, pass.. pass validations.
Any advice? Thank you.
My advice is that I think that two forms for a situation like this is unnecessarily complicated unless there is some application specific imperative to decouple the username/password capture and the CAPTCHA check.
You're probably right to be concerned about using the session to store the intermediate data but if you do want to go that way there's a great screencast showing the technique for a similar application here.
Personally I would go the Javascript route. Load both forms at the same time, step 1 being visible and and step 2 being hidden. Validate step 1 with an AJAX call to the server (if you need that) or client-side if you don't. If step 1 is valid then unhide the step 2 form (and optionally hide the step 1 form if you like).
UPDATE: Adding further info at questioner's request
There are lots of ways to hide and show page content but a common approach is to wrap it in a <div> block marked hidden using CSS and then use some Javascript (e.g. JQuery) to toggle it hidden or unhidden. Like this:
<div id="step2" style="display:none">
<% form_for .... %>
<% end %>
</div>
When the page is loaded for the first time the form will be hidden. Then in JQuery (for example) do:
$(function() {
$('#step2').show();
});
to unhide it. See the documentation for show, hide and toggle for more usage examples.
If you need something simple, you can retain the parameters in the second step using hidden fields.
If you need something more complicated (multiple steps, comming back to previous step, partial validations, etc) you may use a wizard plugin. Here is a list of wizard plugins from Ruby Toolbox.
There are lots of ways of doing this.
railscast #217, demostrates a generic way of dealing with multistep forms, capable of handling tricky things like going forwards and backwards multiple times. Give it a look.

How to blank out a field in an MVC app using TinyMCE

I've got an MVC app that gives the user textarea's to update some description fields. It's strongly-typed to a table object, and the fields are wrapped in a form with a Submit button.
Occaisionally they don't want any data in a field, but when they delete the text and try to save, the blanked-out field comes back with its original text (i.e. the table object passed to the Save action contains other edits, but attempts to blank out fields result in the original text staying in the field).
I'm assuming this is LINQ trying to determine which fields have been edited, but how do you tell it that it's blank on purpose?
UPDATE: It appears this may be a problem with the TinyMCE jQuery plugin. It adds rich-text functionality to textarea controls. If I turn it off, I can remove text with no problems.
UPDATE 2: It seems to be some kind of javascript bug or something. If I put another dummy field after the problem fields, they work. If I move them to another place in my code, they work. They just don't want to work where they are. Very peculiar.
I'm pretty sure that TinyMCE, by default, puts in <p></p> when the control is emptied.
So if you are checking for "" then you may be disapointed.
This initially caused me some issues but never with saving. I was checking if the field was "" and then doing something else. Once I realised that "" was never going to happen, I adapted my validation accordingly.
I just check that on a recent project using TinyMCE editor, but it indeed send "" for an empty input, and during the implementation we had no issues with that.
alt text http://diarioplus.com/files/pictures/tiny.PNG
The body property is the one with a tinyMCE editor on the client side.
I really think it will be something with the modelBinder or the way you set the values back to the model.

Resources