Where is a correct place in code to write validation(adding maximum lenght on text field) depending on two diference input's. User can chose an textfield size between h1 or h2. When user chose h1 I want to limit text to 10 elements, when chose h2 limit will be 7 elements. I use AEM 6.2.
I try to Validate an htl file, validate an cq_dialog.When I try to validate an htl file I have an problem with implementation ( it doesn't work), but in cq_dialog.xml file I can only validate an text label once, and I can't change a logic that my validation was change depending which size of text user chose.
This is My cq_dialog code and the most comfortable for me will be adding all logic here but I don't know this is posible?
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Text"
sling:resourceType="cq/gui/components/authoring/dialog">
<content jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/container">
<items jcr:primaryType="nt:unstructured">
<column jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/foundation/container">
<items jcr:primaryType="nt:unstructured">
<title
jcr:primaryType="nt:unstructured"
name="./title"
fieldLabel="Text"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldDescription="Max 10 elements"
/>
<type
sling:resourceType="granite/ui/components/foundation/form/select"
fieldLabel="Type"
name="./type"
jcr:primaryType="nt:unstructured"
>
<items jcr:primaryType="nt:unstructured">
<h1 jcr:primaryType="nt:unstructured" text="H1" value="h1"/>
<h2 jcr:primaryType="nt:unstructured" text="H2" value="h2"/>
</items>
</type>
</items>
</column>
</items>
</content>
You have to create a clientlib and add JS to register a validator for this use case. The clientlib's category must be referenced by the dialog. Using some OOTB category used by the dialog like 'cq.authoring.editor' will make your clientlib work for dialog validation.
Once you have the clientlib set up, register the validator with the granite framework. Refer https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/coral/foundation/clientlibs/foundation/js/validation/index.html#validator on how to register the validator.
Here's a sample of how you can do this for your usecase.
var foundationRegistry = $(window).adaptTo("foundation-registry");
foundationRegistry.register("foundation.validation.validator",{
selector: "[name='./title']",
validate: function(el){
var text = el.value;
var type = $("[name='./type']").val();
var limit = type === 'h1' ? 10 : 7;
var numberOfElements = getNumberOfElements(text); //not sure what number of elements means in your context
if(numberOfElements > limit){
return "The input cannot exceed "+limit+ " elements for type "+type;
}
//the field is considered invalid if this method returns a string,
// the string returned is also used as the error message.
}
});
* the code has not been tested
Since the category of the clientlib is generic, this validator will be bound for all dialogs. You can either make the selector of the field more specific or change the clientlib category and explicitly reference it only on this dialog.
Related
Have been looking for this answer in SO, but perhaps I'm not frasing it correctly or there is actually no answer yet for this.
I am using an input component that uses a key to render it valid (green border) or invalid (red border) and I would like to add it dynamically:
<Input type="select" valid /> //This input has green border
<Input type="select" invalid /> //This input has red border
Since they key valid/invalid has no value like true or false, I'm not sure how to change it dynamically through a function since as far as I'm aware, I can change values dynamically with a JSX expression, but not add a key itself.
Can you please suggest a way to add 'valid' or 'invalid' tag dynamically without value?
"Without value" is actually not accurate. What you see there is syntactic sugar for valid={true} and invalid={true}.
So, the same can be accomplished by:
const valid = // whatever logic here to determine if it's valid.
<Input type="select" valid={valid} invalid={!valid} /> // Either return or assign to something.
Alternatively:
let inputProps = {type: 'select'};
if (/* whatever logic here to determine if it's valid*/) {
inputProps.valid = true;
}
else {
inputProps.invalid = true;
}
<Input {...inputProps} />; // Either return or assign to something.
But the latter is a lot more verbose.
Not sure if this will work but give it a try.
JSX reads properties without values/= as boolean/true.
Set null values:
<Input type="select" invalid={null} />
You can then conditionally show valid or invalid input elements
I am setting array of strings(strings dynamic values)in custom property (text box) at alfresco form share.but I need to allign them in proper rows and columns.How to allign dynamic array values in the proper table(inside text box)
//Task Script :-
xyz.bpmn
var stringcollection = "Column1:"+value1+" "+" :"+Column2+"value1 "+"End Date: "+stopDate+""................ further concatinated strings.
execution.setVariable('abc:def', stringcollection);
I need to sort these collection of strings in rows and columns inside text box in task form(workflow alfresco share).
//Share UI visibility with custom size text box.
sharecustomconfig.xml
<config evaluator="task-type" condition="abc:taskname">
<forms>
<form>
<field-visibility>
<show id="abc:def"/>
<show id="packageItems" />
<show id="bpm:comment" />
</field-visibility>
<appearance>
<field id="abc:def" label="abcdef" read-only="true">
<control template="/org/alfresco/components/form/controls/textarea.ftl">
<control-param name="style">color: black</control-param>
<control-param name="rows">6</control-param>
<control-param name="columns">6</control-param>
</control>
</field>
</appearance>
</form>
</forms>
</config>
Define a property in your model file
In your share-config-custom.xml define form field to render
'" field id="your:prop" set="details" label="details" read-only="true" '"
"control template="org/alfresco/components/form/controls/workflow/custom.ftl" "
Define a property which will show your table Define a custom ftl as form field. And pass your variable to this ftl write your logic to sort list of your string in row and column and you can render it in table in your ftl file
Can someone please supply proven code for this. I've looked throughout stackoverflow, several other forums and articles. The questions is being asked often and the answers very similar, but the responses are invariable that the supplied solution does not work. Here's one that I've tried. We'll say I've entere http://www.amazon.com into the inputText and I'm trying to replace http://www.brisnet.com/cgi-bin/trk_report.cgi?drs#
xhtml
<h:inputText id="newUrlId" styleClass="bodyTextMediumIndent" size="100" value="# {hhraDrf.newDrfUrl}" />
<h:commandButton id="goBtnId" onclick="refreshUrl()" value="Go" />
<divid="objectDivId">
<<object
id='drfId'
style='object-fit:contain;'
data='http://www.brisnet.com/cgi-bin/trk_report.cgi?drs#'
type='text/plain'
width='1024px'
height='768px'>
</object>
</div>
javascript
function refreshUrl() {
myUrlValue = document.getElementById('hhraFormId:newUrlId').value;
objectElement = document.getElementById('drfId');
objectElement.style.display = "none";
objectElement.data = myUrlValue;
objectElement.style.display = "block";
}
I've put alerts in the javascript and myUrlValue is = http://www.amazon.com. alerts also indicate the correct current, original value of the object data as http://www.brisnet.com/cgi-bin/trk_report.cgi?drs#
In reality, it's simply redisplaying the original data element as http://www.brisnet.com/cgi-bin/trk_report.cgi?drs# and a check of the page source indicates it's still there.
I'm simply trying to change the URL and get it to redisplay that URL.
1. this is .xhtml file
there is a ...xhtml page and in that page's p:dataTable included another page i.e plandata.xhtml and in plandata.xhtml we have written:
< h:commandLink value="#{plan.rmsId}"
action="#{planBean.viewPlanAction}" ajax="false">
< f:param name="rmsPlanId" value="#{plan.rmsId}" />
< f:param name="planStatus" value="#{plan.planStatus}" />
< f:param name="pendingWith" value="#{plan.pendingWith}" />
< f:param name="pendingWithRole" value="#{plan.pendingWithRole}"/>
and this is bean code:
pendingWithVar = myRequest.getParameter("pendingWith");
if(null == pendingWithVar){
pendingWithVar = planMapping.getPendingWith();
}
plan.setPendingWith(pendingWithVar);
String pendingWithRole = myRequest.getParameter("pendingWithRole");
if(null == pendingWithRole){
pendingWithRole = ""+planMapping.getPendingWithUserRole();
}
I have used f:param tag with commandLink. But when right click and select view source option it shows that parameter value and i want to hide that values.Is there any solution on this?
What you can do is use <f:attribute .../> (it's not shown in the source).
<h:commandLink ...>
<f:attribute name="pendingWith" value="#{plan.pendingWith}"/>
<f:attribute .../>
</h:commandLink>
To obtain the value your backing bean, you need to obtain your UIComponent instance (you can use the binding attribute of h:commandLink and do:
myUiComponent.getAttributes().get("format")
(JSP - GRID)
I have a grid that load data, i use a formatter="formatLink" in a column for add aspect hyperlink with the respective value of the cell,
<s:url id="remoteurl" action="lisaluXCodYNom" namespace="/"/>
<sjg:grid
id="gridtable"
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="clientes"
reloadTopics="reloadMyGrid"
rowList="10,15,20"
rowNum="5"
rownumbers="true"
formIds="mcp"
onSelectRowTopics="rowselect"
>
<sjg:gridColumn name="codcli" index="codcli" title="Codigo" sortable="false" formatter="formatLink"/>
<sjg:gridColumn name="nomcom" index="nomcom" title="Alumno" sortable="false" width="300"/>
<sjg:gridColumn name="facultad.desfacres" index="desfacres" title="Facultad" sortable="false"/>
<sjg:gridColumn name="escuela.desesc" index="desesc" title="Escuela" sortable="false"/>
</sjg:grid>
(JAVASCRIPT)
FormatLink, changes the content by hyperlink,
openDialog, executes the action, sending the value of the selected cell in the grid. I capture that value in the object "cliente.getCodcli (cliente.codcli)"
<s:url var="ajax1" action="seleccionarfila" />
function formatLink(cellvalue, options, rowObject) {
return "<a href='#' onClick='javascript:openDialog("+cellvalue+")'>" + cellvalue + "</a>";
}
function openDialog(employee) {
//When I click on any link brings me here
$("#divresult").load("<s:property value="ajax1"/>?cliente.codcli="+employee);
}
(SAME JSP - DIV FOR UPDATE)
I would like this div is upgraded with the information brings back the action on object "cliente.codcli"
<sj:div id="divresult"
dataType = "json" >
</sj:div>
MY STRUTS
As you see i return all object "Cliente", because I need all the attributes in momery to be updated each div with respective atribute.
<action name="seleccionarfila" class="intranet.ConsultarAlumno" method="CargarDatos">
<result type="json">
<param name="root">
cliente
</param>
</result>
</action>
MY METODH "CargarDatos"
This method does what in reality is: Fill a Object with the name "Cliente" that brings its attributes, "name", "surname", "phone", etc etc.. Based on the value of the selected cell (which is really is a code of any client)
public String CargarDatos() {
cliente = new Cliente();
cliente.setCodcli("2008502240");
cliente.setNomcom("ORTIZ");
cliente.set(New Object());
cliente.getObject.setOtherData1("OtherData"));
cliente.getObject.setOtherData2("OtherData2"));
return SUCCESS;
}
So the question goes like this:
Clicking on a row, captured the value of the cell with title "Codigo" then my "seleccionarfila.action " is executed. In the method "CargarDatos" fill an Object with name "Cliente" (filled by hand just for this example, and as can see I have 3 attributes in the Object "Cliente": "codcli", "nomcom" and other object .... "Object" with your attributes)
Well, the upshot of all this is that the div with name "divresult" is updated with all the object "Cliente" and show it with {} and everything else, and only one div is updated.
So, my problem here is:
I need to update many div in the same page.
The divs should are based on a object "Cliente"
The Object "Cliente" should fill based in the click of row the enter
code here enter code here grid
Each attribute of this object 'cliente' respective update a div.
Example:
Div1 = Cliente.codcli
Div2 = Cliente.nomcom
Div3 = Cliente.Object.OtherData1
Div4 = Cliente.Object.OtherData2
etc...
That's what I can do?
chances are that the grid componet let me make an easier way. maybe I'm complicating unnecessarily.