Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Audience Targeting Custom User Segement Rule
			Hi Team,
I am creating Custum rule for audience targeting - we have form which validates value - value is mandatory
I have validated with custom javascript code but when we save the form validation is not working
with empty value also its creating user segment - any settings or property we need to add?
Please suggest- Thanks in advance.
		
		
		I am creating Custum rule for audience targeting - we have form which validates value - value is mandatory
I have validated with custom javascript code but when we save the form validation is not working
with empty value also its creating user segment - any settings or property we need to add?
Please suggest- Thanks in advance.
			Hi Bharamani,
When adding javascript in a Custom Rule in Audience Targeting, it is specially important to pay attention to the namespacing. That could be the reason why your JS validation is not working. Could you please tell which version of Liferay and AT you are using? This way we can guide you with some examples.
Regards
		When adding javascript in a Custom Rule in Audience Targeting, it is specially important to pay attention to the namespacing. That could be the reason why your JS validation is not working. Could you please tell which version of Liferay and AT you are using? This way we can guide you with some examples.
Regards
			Hi Eduardo,
I am using Liferay 7.1 DXP
and liferay audience targeting.lpkg file compatible downloaded from customer site.
Once we create user segement for custom rule - on clicking save or 'save and continue' button the validation should work.
Thanks
		I am using Liferay 7.1 DXP
and liferay audience targeting.lpkg file compatible downloaded from customer site.
Once we create user segement for custom rule - on clicking save or 'save and continue' button the validation should work.
Thanks
			Hi Bharamani,This is an example of a rule with validation: https://gist.github.com/epgarcia/a7cf6d40d47845016e1de2e5d330ebfdOne extra question: is your custom rule multi-instanceable (i.e. it can be added more than once to the rule builder)?
		
		
			Yes, custom rule multi-instanceable. 
And I have used your example as well - same behavior
https://gist.github.com/epgarcia/a7cf6d40d47845016e1de2e5d330ebfd
Steps : 1> Created custom module of template 'content-targeting-rule'
2> replaced view.jsp with content you shared.
3> still i am able to save with empty 'to' and 'from' fields.
Do we need to override edit_user_segment.jsp to validate our rule inside 'savefields' and 'saveAndContinue' js functions?
Do we have any Liferay Documentation available to refer?
I searched - No link reference available for 7.1 version(For Audience targeting).
		And I have used your example as well - same behavior
https://gist.github.com/epgarcia/a7cf6d40d47845016e1de2e5d330ebfd
Steps : 1> Created custom module of template 'content-targeting-rule'
2> replaced view.jsp with content you shared.
3> still i am able to save with empty 'to' and 'from' fields.
Do we need to override edit_user_segment.jsp to validate our rule inside 'savefields' and 'saveAndContinue' js functions?
Do we have any Liferay Documentation available to refer?
I searched - No link reference available for 7.1 version(For Audience targeting).
			Hi Bharamani,The code I shared is valid for non-instanceable rules (default case). For multi-instanceable, you need to include an extra namespace. See:https://gist.github.com/epgarcia/178df066245955b7288885549a36d581
You can see how it works in instanceable rules such as Role Rule, for instance. If you still don't get it to work, please share your code and I'll help you.Regards
		You can see how it works in instanceable rules such as Role Rule, for instance. If you still don't get it to work, please share your code and I'll help you.Regards
			Hi Eduardo,
can you please help me with the steps to execute default case so that i can apply same in my rule.i am not sure but some where some setting or property need to be added.. because when u click save its not validating rules..
		can you please help me with the steps to execute default case so that i can apply same in my rule.i am not sure but some where some setting or property need to be added.. because when u click save its not validating rules..
			Hi Bharamani,I'd recommend that you start with a very simple rule with just one field, make sure it validates, and then start adding other fields and their validators. Could you try with a simplified version? For instance, only one input text field and its validator for "required". I observed some issues with your code. You're setting the id of the aui:input. This is tricky, because the taglib builds this id automatically from the name and prefixes it with the portlet namespace. If you set it manually, then you'd have to include the namespace yourself. I'd recommend that you only set the name attribute, and leave the taglib set for you. 
When setting the name, since your rule is multi-instanceable, add the ContentTargetingUtil.GUID_REPLACEMENT. For instance, ContentTargetingUtil.GUID_REPLACEMENT + "myField".Let me know if it works.
		When setting the name, since your rule is multi-instanceable, add the ContentTargetingUtil.GUID_REPLACEMENT. For instance, ContentTargetingUtil.GUID_REPLACEMENT + "myField".Let me know if it works.
			Hi,
As i told .. i tried with simple example you shared for default case with IP address to and from. I am unable to figure out exact cause.
And If you see my view.jsp - its validating when i click outside the box but when i click save it does not validates.
I request you to provide sample end to end working blade sample.
Thanks
		As i told .. i tried with simple example you shared for default case with IP address to and from. I am unable to figure out exact cause.
And If you see my view.jsp - its validating when i click outside the box but when i click save it does not validates.
I request you to provide sample end to end working blade sample.
Thanks
			Hi Bharamani,Sorry, you were right. That code should be working, but there's an issue with the JS validation in the segments rules (See https://issues.liferay.com/browse/WCM-1513). I wasn't aware of it. Until we provide a fix for it, you can provide server-side validation by checking the field values in the processRule method of your Rule class, and throwing an InvalidRuleException when they don't have the right values.Sorry again for the misunderstanding.Regards
		
		
			HI Eduardo,
any tentative date for next fix pack which includes above issue resolution?
Thanks
		any tentative date for next fix pack which includes above issue resolution?
Thanks
			Thank you guyss