Orchard Fields Validation - orchardcms

In Orchard 1.4.2, when fields like input field are marked as required, validation pop up appears. How is the validation happening without re-directing the user to another view?
To explain in details, If I have a form that I have attached to a page, the form field validation displays an error message ( may be it is through AJAX or javascript), but there is no re-direction to the 'form' view - it stays on that page view.
I need to add validation to another module without it re-directing to another view.
Any idea?

You can find this bit of code in the InputFieldDriver class...
if (settings.Required && string.IsNullOrWhiteSpace(field.Value)) {
updater.AddModelError(GetPrefix(field, part), T("The field {0} is mandatory.", T(field.DisplayName)));
}
Adding a model error will send the user right back to the same page.
FYI, the fields module is a sub repository located here: https://orchardfields.codeplex.com/
The class I'm talking about is right here: https://orchardfields.codeplex.com/SourceControl/changeset/view/4d125be1a6b3#Drivers%2fInputFieldDriver.cs

Related

Why is the wrong form opening when I click the doc link I created from a SSJS function?

Ok, this is weird. I created an xpage input form. After the form is filled out, a document is created. I then create an email to notify people that the document has been created. I drop a doclink to the newly created document in the body of the email. During testing, I noticed that when I click the link in the email, the wrong Notes Form is opened. Instead of the 'TrainingRequest' form displaying the fields, the form 'Feedback' opens up instead. Here's what I checked:
- On the xpage data section, the 'form' is set to 'TrainingRequest'.
- When I open the document via the doc link, the field 'form' has the value 'TrainingRequest', which is correct. Yet it's displaying the 'Feedback' form.
- When I check the other field properties of the document, all the correct fields from the 'TrainingRequest' form are there and populated correctly.
- When I open the document via the view, the correct Notes form 'TrainingRequest' opens.
- There is no default form in the database design.
Has anyone seen this before?
thanks
clem
Doc links are always created using the default view of your application. If there is a form formula in this view then this overrides the form in the document. Remove the form formula of the default view and it works.
I almost NEVER use form formulas in my application because of the side effects.
Source code would be useful. But initial best guess based on what you're saying is you have two datasources on the XPage, neither have ignoreRequestParams set, so you're editing the same document with both data sources. ignoreRequestParams missing will ignore any properties you define.

404 Item not found When Providing access to existing documents from an XPage View

I have been following the tutorial here for creating an XPage application. Unfortunately I am encountering an Error 404 HTTP Web Server: Item Not Found Exception when you try to follow a link to another document from the main view XPage. Everything else seems to function properly until that point.
It happens when you select "XPage associated with the documents form".
According to some googling I simply needed to rebuild my project but that didn't work. That was the only fix I was able to find.
The link for my xpage for my view is : http://localhost/ExpenseClaims.nsf/xclaimsview.xsp
The link to a xpage with the 404 error from my view is: http://localhost/ExpenseClaims.nsf/%24%24OpenDominoDocument.xsp?documentId=15DA9966C77908D385257C150070483D&action=openDocument
The problem has returned for my "claim" xpage that represents a form document named "claim". My response documents open as needed.
My associations are:
Views: Xpage:
Claims -> xclaimsView
Forms: Xpage:
claim -> claim
response -> response
Most likely the connection between your XPage and the form didn't work. Open the form, then in the properties pick the XPage you want to open. Save it and try again.
There's one special case when you have an XPage with the same name as the form, where that should happen automatically, but it is safer if you specify the property in the form (second tab on the property box)
The data connection from the xpage to the form seems to be breaking down that's a possible cause but not an acceptable answer. The reasons are everything from the project build being broken to the port that domino designer is using as default being occupied.
Cleaning then building the project may help (Project -> Clean) but in my case it didn't. Opening the Page by selecting it by name is helpful but not if you are opening two different pages from the same view(View Properties -> at run time open selected document). There was another suggestion that said to move the default domino test port(File -> Preferences -> Domino Designer) but that didn't work for me.
The final answer was to go to each form's properties box and link it to it's corresponding xpage (second tab form properties). (see answer marked as correct for a link to IBM with a better explanation)

Unable to get document page name for

I have a view that has XPage Associated with document form set.
The form property has the xpage associated with the document.
If I click on the link in the view the proper correct xpage is displayed as expected.
But if I close the browser, and paste the URL to the document into the browser, I get the error, Unable to get document page name for (and the unid). As long as I remain logged in the url will work without error or if I set anonymous to Reader the url will continue to work. But if I close the browser where I would be prompted to login then I get the error but I get the error before being prompted to log in.
The url for assocated forms looks a little different than when the view is used to display the xpage.
myserver/mydb.nsf/$$OpenDominoDocument.xsp?documentId=12B571F2B03E3764852573690041E273&action=openDocument
The view has various types of forms so I need to associate the form with the xpage or I suppose I can compute the xpage for the form. But any idea what would be causing this issue?
If you are opening a document from a view, the associated form could be overriden by a form formula of the view. When opening the document directly with $$OpenDominoDocument.xsp the original form stored in the document is used instead.
The form can be associated with a XPage in different ways:
For XPiNC there is a field $XPagesAltClient in the form
For web access there is a field $XPagesAlt in the form
There is a entry in the xsp.properties file.
For example this entry...
xsp.domino.form.xpage.foo=bar
...will open a document with the value foo in the Form field with the XPage bar.xsp.
Hope this helps
Sven

CakePHP 2.1: Using CSRF protection on Elements

I have a somewhat special situation with one of my CommentsController actions, the "add" action.
Since I have an "Add Comment" form on my "view" View of PostsController, I have an "add_comment" Element instead of an "add" View for the Comments. This is that I can just insert the Element with the form inside the "view" View of Posts. I hope this does not sound too complicated.
Now, inside the "add_comment" Element, the form gets submitted to the actual "add" action of CommentsController. If the form has to be rendered again, because of invalid user input for exaxmple, the form gets rendered again by - this time - calling the "add" View of Comments. This "add" View only again includes the "add_comment" Element, which - as was said above - includes the actual form.
Now the thing is, I added the Security component to my CommentsController in order to get CSRF protection. All my admin actions of CommentsController get the protection i.e. e token is rendered inside the form and checked upon submitting the form.
Still, the add_comments Element form does NOT get a token. Probably because it is an Element and not the corresponding View.
How can I manually insert a token into the Element's form or how do I better solve this?
Thank you
EDIT: Se also my other question regarding the setup - it should explain it a little
EDIT2: This is what's inside my add_comment Element
EDIT3: This is the HTML output of the add_comment element. The nonce should be in the <div style="display:none;"> part.
EDIT4: I put Debugger::log($this->Form->request->params); inside the element (add_comment.ctp) and the view (add.ctp) and this shows the output.
I also uploaded the the whole CommentsController (here). Please note that I specified a blackhole function to catch errors of type 'auth'. This is because, every time I entered invalid data in the add_comments.ctp Element and - by submitting the form - the actual add Action of CommentsController was invoked (and thus the add View of comments), I got a blackhole error of type 'auth', which I could not explain so I caught it with this way - this might even be related to my problems.

Using standard validation for read only edit boxes?

Some of my recent posts have to do with the fact that I am doing all of my validation in my Submit button.
The reason I am doing this is that I have a button that sets some read only edit boxes. Well you can configure a validation for a read only edit box but it does not execute at run time.
Since I could not figure this out and wanted to have a consistent look for validation I used my own validation on my Submit button.
Is there a way to validate read only fields?
One nice thing about putting all of the code in the Submit button is that all of the validation code is all in the same place but I can see where it also can cause portability issues when using custom controls.
Also another question is how to fire off validation if my Submit button is not marked as a Submit button.
As Dec says, the ReadOnly flag causes the content of the field to be rendered without the <input> tag. This makes validation impossible on the client side and since there is no data being submitted back to the JVM, validation coded on the field is ignored on the submit.
However, the data source QuerySaveDocument is triggered. Put your validation in there and/or put it in the fields that are rendered (readOnly=false) and be sure to set disableClientSideValidation="true" on all fields with validators on them.
Your QuerySaveDocument code looks something like this (assuming location is the field which is readOnly).
if (personDoc.getItemValueString("Location") == "") {
#ErrorMessage("The inherited location is blank and that is bad.");
return false;
}
return true;
With this, the field based validators will fire first and if they are all successful the QuerySaveDocument fires. This means if any field based validators fail, their messages will appear in your message area but the QuerySaveDocument message will not appear. QuerySaveDocument messages ONLY appear after all field based validators succeed.
When a read only field is rendered to the web browser it does not render using <input> tags but rather a simple <span> tag.
Validation can only be performed on proper input tags so the scenario you are experiencing is correct. There is no field for it to validate in read-only mode.
There is an option to 'display disabled in read only' which will render an <input disabled="true"> type tag for the field but I'm not sure off the top of my head is validation will work for those fields either because if a field is read-only then there really should be no need for any validation because your programmatically putting the value into the field and you should be validating it programmatically before you add the value.

Resources