aui:validator tag not working in jsp page - liferay-6

I'm working on liferay version 6.1.1 , Below the code given for liferay aui validator , which not working on jsp pages
Syntax type 1 -
<aui:input name="fname" type="text" value="" class="input-xlarge" id="fname">
Syntax type 2 -
<aui:input name="fname" type="text" value="" class="input-xlarge" id="fname" >
<aui:validator name="required"></aui:validator>
</aui:input>
I need the solution very soon , Thanks in advance

I did not manage either until I added in portlet.xmL:
<init-param>
<name>add-process-action-error-action</name>
<value>false</value>
</init-param>
This might help,
Gerbrand

Hi Please have look into following links
http://www.liferaysavvy.com/2014/01/form-validation-in-liferay.html
http://www.liferaysavvy.com/2013/12/liferay-aui-validator.html

Check javascript error in your page.
inspect element then go to console, generally this error happen only if there is any error in javascript in our page.
Resolve that javascript error and they try.
I also faced same issue, I did lots things but just remove the error of javascript and then it is working prefectly.

Had the same issue. Make that your input field is in an aui form
<aui:form ...>
aui .... input fields here
</aui:form>
Read this

I had a similar problem. I fixed it by putting a name to the aui:form containing the aui:input.
I don't know why validators requires a form name, yet it works.
<aui:form action="${URL}" name="putANameHere" cssClass="form-inline">
I hope it works for you

Related

Gorilla CSRF - Forbidden - CSRF token invalid - fails when there are two forms

I'm adding in CSRF token validation and I'm running into a problem where I have two forms on a page and one of them will submit successfully and the other will not. I'm not doing AJAX requests, I'm simply using hidden input fields. If I submit the form when it is the only one on the page, it submits without issue. If I submit it on a page with more than one form, it fails.
Below is the template code for my two forms
{{if .IsAuthenticated}}
<form action='/admin/logout' method='POST'>
<button>Logout</button>
{{.CsrfField}}
</form>
{{end}}
<form action='/admin/stuff/create' method='POST'>
{{with .Form}}
<div>
<label>Title:</label>
<input type='text' name='title' value='{{.Get "title"}}'>
</div>
<div>
<input type='submit' value='Publish stuff'>
</div>
{{end}}
{{.CsrfField}}
</form>
And this is what the generated HTML looks like. Both appear to be valid.
When I click the "Logout" button though, I get the Forbidden - CSRF token invalid error, but clicking the create input value in the second form always works.
The logout button is correctly validated when I attempt to use it on the home page which is "/admin/" but it does not work on any of the other pages "/admin/snippet/:id" or "/admin/snippet/create". The Logout button is part of a base template, so it appears on every page, so there shouldn't be anything different in how it appears on any page.
I've read other SO posts about multiple forms & CSRF tokens on a page and I understand there should be no issue with multiple forms with the same information as long as you have each one in it's own form, it should be fine. So I am not sure where I am going wrong.
I found the issue. Currently the way that gorilla/csrf works, it does not like creating the masked token from one path and then sending that token off to another path. So in my situation, going from /admin/snippet/create to /admin/logout threw an error because it was expecting the path for the token to be /admin/snippet/<something> and so it threw an error.
This issue has been addressed in this PR: https://github.com/gorilla/csrf/pull/147 and essentially the solution is to set the default path yourself to something which all of your routes will contain, so in my case that was /admin
This is what my CSRF declaration looks like now in main.go
var csrfMiddleWare = csrf.Protect(
[]byte("<put your 32 character key here>"),
csrf.Path("/admin"),
csrf.Secure(false),
)
A note, if you had this issue and then apply this fix and it doesn't resolve the problem, trying testing in a separate browser as there may be some caching issues.

Can i use ngxErrors or something like it to display a form error?

I use ngxErrors to display errors for a form control and it works great. Is there any way to get similar functionality for a form or a form group? Currently, I display a form error like this:
<div *ngIf="form.hasError('loginFailed')">
Login Failed
</div>
The bummer is, when I detect that there is a form error (e.g. after the login form is submitted) as opposed to control error, I set it like this:
this.form.setErrors({ loginFailed: true });
this.cdr.detectChanges();
Where this.cdr is an instance of ChangeDetectorRef. This is necessary because I'm using OnPush change detection strategy. So basically it's like calling $scope.$apply() from AngularJS all over again.
What I would really like to do is something more like how ngxErrors does it:
<div ngxErrors="myForm">
<div ngxError="loginFailed" [when]="['dirty', 'touched']">
The login has failed
</div>
But ngxErrors expects myForm to be a control.
This feature is not currently baked into ngxErrors, but I submitted a PR. https://github.com/UltimateAngular/ngxerrors/pull/18
The working syntax is a slight modification of the above:
<div ngxErrors>
<div ngxError="loginFailed" [when]="['dirty', 'touched']">
The login has failed
</div>
</div>
I learned that you do not have to tell child components the form, the FormGroupDirective is available to children automatically.
See this library https://www.npmjs.com/package/ng-error-messages for show error messages based on validation rules:
<input placeholder="Texto:" formControlName="text">
<div errorMessage="text" alias="Super Texto" ></div>

We want to have a customized subscription form, that includes a coupon code input

As I understand it - I cannot use Recurly.js v3 for this... the hosted pages are not very pretty - so we want to style our own, however it seems like the coupon code field is not supported - and its very necessary for our business model.
Am I missing something?
It's definitely supported. Just add an input and use the data-recurly="coupon" attribute:
<input type="text" data-recurly="coupon">
You can see it in the pricing section of the R.JS docs.
I have integrated this into my application in few weeks ago. You can add the following to your page for the coupon code field.
<input type="text" name="couponcode" placeholder="Coupon Code" data-recurly="coupon_code" >
You can get the value by input field name name="couponcode". Following is the PHP code.
'coupon-code' => sanitize_text_field($_POST['couponcode'])

Spring MVC REST PUT is not working

I have the following problem: Whenever I try to edit the following data, I get an exception saying that HTTP PUT is not supported by this URL. This is the JSP form side of things where a button is used to edit that row:
<c:url var="formAction" value="/circuits/${circuit.circuitId}" />
<form:form method="PUT" action="${formAction}">
<input type="hidden" name="circuitId" value="${circuit.circuitId}" />
<input type="submit" value="Edit" class="btn btn-primary" />
</form:form>
And the following is my controller method that retrieves the circuitId:
#RequestMapping(value = "/{circuitId}", method = RequestMethod.PUT)
public String showEditCircuitForm(#PathVariable Integer circuitId, ModelMap model) throws NoSuchRequestHandlingMethodException
However, when I use the normal GET method everything works fine, it's just this PUT method that is causing the problem. I have got all the dependencies that I need.
Only getand post are officialy supported with forms. I'm not aware of any browser that supports put with forms. It is supported with AJAX, though.
Apart from that the support of the Java Servlet API for PUT is not ideal. You might need to include a filter in your web.xml:
<filter>
<filter-name>httpPutFormContentFilter</filter-name>
<filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
</filter>
Before I forget: You can send a post request and use another filter to fake a put request:
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
To get this working you have to include a hidden field with the name _method and the value PUT in your form.

grails form redirect gives 404, but url mapping works

I feel like I've entered the Twilight Zone. I have a Grails form that redirects to a URL, but gives a 404. If I go directly to that exact URL, everything works fine (that is, the URL mappings are correct).
This is an example generated form tag:
<form action="/alm/contactRefresh/itemRefreshProcess/7070" method="post">
On submit, it redirects to:
http://localhost:8080/alm/contactRefresh/itemRefreshProcess/7070
But gives this error:
HTTP ERROR 404
Problem accessing /alm/contactRefresh/itemRefreshProcess/7070. Reason:
NOT_FOUND
Powered by Jetty://
But then if I just go directly to that same URL (by focusing the browser Location bar and pressing enter), the page renders just fine, though the form params are lost because it's just a GET now. I've also tried changing the form method to GET, and that doesn't work either (throws a 404).
I've done similar forms a zillion times before with no problems. I'm sure this is some stupid user error, but I seriously can't figure out what's wrong.
Thanks for any ideas!
So, I finally started ripping parts out of the form and found out that for some reason you can’t name a Grails checkbox starting with the word "action". It must be something related to the default params["action"] entry. Though my checkbox names were a concatenation of "action_" + an id.
Anyway, there was some kind pre-processing of the checkbox form params that was blowing up before making it to the controller, and somehow that translated to a 404 instead of an actual Exception.
Originally I had this:
<g:checkBox name="action_${serviceRefreshAction.id}" value="${true}" />
Which renders this:
<input type="hidden" name="_action_7196" /><input type="checkbox" name="action_7196" checked="checked" id="action_7196" />
I changed "action" to "myAction", like this:
<g:checkBox name="myAction_${serviceRefreshAction.id}" value="${true}" />
Which renders this:
<input type="hidden" name="_myAction_7206" /><input type="checkbox" name="myAction_7206" checked="checked" id="myAction_7206" />
And now everything works fine.
Five hours of my life down the drain.
But I guess I have to forgive Grails, for the all time it saves me on a daily basis normally. :o)