How to add Today() in DojoDateTime in XPages - xpages

I would like to add today functions anywhere in this component which sets the field as Today.
is it possible to do?
COMPONENT CODE:
<xp:inputText id="EvrakUlasimTarih" value="#{document1.EvrakUlasimTarih}"
valueChangeListener="#{changeRequestBean.valueChangeListener}" dojoType="dijit/form/DateTextBox" styleClass="fs-12 datetimeStyle">
<xp:dateTimeHelper id="dateTimeHelper2"> </xp:dateTimeHelper>
<xp:this.converter>
<xp:convertDateTime type="date" dateStyle="short">
</xp:convertDateTime>
</xp:this.converter>
</xp:inputText>

The component is open source, so yes, it's possible. I'm not aware of anyone who's extended the control to do that though. I suspect you would need to extend the renderer and add a function to jump to today's date in the JavaScript library incorporated by the renderer, but I may be over-simplifying it.

Can you set the default value of the inputText to #Today()? May be this set the component to the current date

Related

Only Allow TypeAhead Values in InputText Field

I'm trying to figure out how to limit a user to TypeAhead values in an InputText field. One thought I had is to run logic onblur that would check the value in the field against acceptable values. My inputText and typeAhead code is below:
<xp:inputText id="TypeAhead">
<xp:typeAhead mode="partial" minChars="2" ignoreCase="true">
<xp:this.valueList>
<![CDATA[#{javascript:db = new Array(#DbName()[0], 'names.nsf');
return #DbColumn(db, "($VIMPeople)", 1)}]]>
</xp:this.valueList>
</xp:typeAhead>
</xp:inputText>
Thanks in advance for any ideas.
Have you tried a dojo FilteringSelect? It's like a combination of a combo box and a type ahead edit box. ExtLib comes with an Xpages version of it.
In case you're not familiar with that you might want to take a look here:
https://dojotoolkit.org/reference-guide/1.10/dijit/form/FilteringSelect.html#dijit-form-filteringselect

xpages decimal separator EditBox

I have a very very simple source code:
<xp:inputText id="inputText3"
value="#{document1.A}"
defaultValue="5.5" type="number">
<xp:this.converter>
<xp:convertNumber type="number">
</xp:convertNumber>
</xp:this.converter>
</xp:inputText>
If I use a European Browser (that use the comma separator for decimal number) only the first time (when load the page) I see the correct information on the field.
If I refresh (partialrefresh for example) the InputBox...I see 55
With USA Browser all work correctly (where the pound is a decimal separator)
I have try play with converter without success...
Have you some suggest to fix this problem?
Tnx a lot
I have solve my problem. The really problem was HTML5 attribute type=number that force with dot my number...
SO that I have created a custom converter and now work correctly:
<xp:inputText value="#{document1.valore}" id="valore1"
type="number" immediate="false" defaultValue="5.5">
<xp:this.converter>
<xp:customConverter
getAsString="#{javascript:value.toString()}">
<xp:this.getAsObject><![CDATA[#{javascript:parseFloat(value.replace(/,/g,"\."))}]]></xp:this.getAsObject>
</xp:customConverter>
</xp:this.converter>
</xp:inputText>
So work if you insert , or . in the inputtext
P.S. Chrome have the problem with the decimal value that don't render the value into the inputbox
I'm not sure if this is correct, but it sounds like the server is sending 5.5 to the browser. However, during the partial refresh, the European browser identifies the "." as a thousand separator so sends the value back to the server as 55, which is then written back to the underlying datasource as 55 and passed back to the browser as 55.
You might be able to confirm that by checking the post data from the browser or adding a custom validator that just prints the submittedValue for the component. It would need to be a validator or converter, in order to run in the Process Validations phase, and so before the value is converted and written back to the field. Server-side 5.5 should be dealt with the same way regardless of the browser.

XPages - using SSJS to update a date field

I'm trying to use SSJS to update a date field. This works fine if the option "Use date/time picker pop-up" is not selected. However if this option is checked, the update does not work. Can anyone explain why this is? Here is my code:
<xp:panel rendered="true">
<xp:button value="Set Date Value" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="DateField">
<xp:this.action><![CDATA[#{javascript:document1.setValue("DateField","01.01.1970");}]]></xp:this.action>
</xp:eventHandler></xp:button>   
<xp:inputText id="DateField" value="#{document1.DateField}">
<xp:this.converter>
<xp:convertDateTime type="date"></xp:convertDateTime>
</xp:this.converter>
<xp:dateTimeHelper></xp:dateTimeHelper>
</xp:inputText>
</xp:panel>
To be able to set a date field you need to set it using a correct date format
document1.setValue("DateField","01.01.1970")
The Date format needs to be java.util.Date so try this
document1.setValue("DateField",new Date("01.01.1970"))
But I would suggest doing it this way because then you code isn't bound to that the server is using that specific locale settings.
var date=new Date();
date.setFullYear(1970)
date.setMonth(0) //remember months starts with 0
date.setDate(1)
document1.setValue("DateField",date)
One thing is that I haven't got this to work when running in a Notes client, but that might be a bug.

Set readonly property inside a nested panel

If I have an outer panel in which the readonly property is true, is there any way to created inner panels in which the content can be editable?
The use case is a mobile page with a number of fields plus multiple RoundedRectLists. I would like to add a search control to each RoundedRectList to filter the content of those lists. I do not want the fields to always be editable. I need the search control to be editable so I can enter a search value without toggling the entire form. At the moment I have readonly=false set for the inner panel but the search control only becomes editable when the readonly for the outer panel is also set to false.
I know I can created separate panel that are not nested, but this design pattern of nested panels is quite common and I am sure there is n XPages guru out there that has solved this...
I am not the XPage guru you are searching for but i have a workaround, =)
As far as i know if you set the outer panel to readonly="true" all your inner inputText boxes will output no <inputField> in your html just a <span>. Thats also very anoying if you want to have a field that looks like a input but is just disabled for input. That is achieved if you set the to disabled="true" and showReadonlyAsDisabled="true".
I would recomend setting all readonly="false" and use dojo.query to set the disabled propertie on page load like:
<xp:scriptBlock>
<xp:this.value><![CDATA[dojo.ready(function(){
dojo.query(".input").forEach(function(node, index, array){
node.disabled = true;
}
)
});]]></xp:this.value>
</xp:scriptBlock>
<xp:panel>
<xp:inputText id="inputText1" value="#{viewScope.in1}" styleClass="input"
defaultValue="Txt0" >
</xp:inputText>
<xp:inputText id="inputText2" value="#{viewScope.in2}" styleClass="input"
defaultValue="Txt1">
</xp:inputText>
<xp:inputText id="inputText3" value="#{viewScope.in3}" styleClass="input"
defaultValue="Txt2">
</xp:inputText>
</xp:panel>
Another benefit of this solution you can set them editable on clientSide without any Server calls.
Hope it helps.

Dynamic binding within a repeat control

In a purchase order module, we need to ask certain questions depending on the source selection method, competition type and total cost of the PO. These questions are likely to change over time and in between different instances of the database.
So I have a view containing the questions, so that I can add questions dynamically to my XPage without needing to change the code. The answer to each question will be stored in a field. So, the document that contains the question has a field called FieldName that is used to supply the field name that will be used. Unfortunately, I am having no luck binding these dynamic fields to the document.
<xp:this.data>
<xp:dominoView var="competitionQuestionView"
viewName="CompetitionQuestions">
</xp:dominoView>
</xp:this.data>
<xp:repeat id="repeat2" rows="30" var="rowData" style="width:700px"
value="#{competitionQuestionView}">
<xp:label id="label1">
<xp:this.value><![CDATA[#{javascript:rowData.getColumnValue("Question");}]]></xp:this.value>
</xp:label>
<xp:inputText id="inputText1">
<xp:this.rendered><![CDATA[#{javascript:rowData.getColumnValue("FieldType") == "Text Box"; }]]></xp:this.rendered>
<xp:this.value><![CDATA[#{javascript:poDoc[rowData.getColumnValue ("FieldName")];}]]></xp:this.value>
</xp:inputText>
</xp:repeat>
I've tried various ways to do this, including making a dynamicInputText custom control to pass in the field name, but without luck. The closest I got was when I used this:
<xp:this.value>
<![CDATA[#{javascript:tmp = rowData.getColumnValue ("FieldName");'#{poDoc.'+tmp+'}';}]]>
</xp:this.value>
That gave me something like #{poDoc.justification}, which was what I wanted to pass to the 'binding', but it ended up displaying as the text value.
I did try using $ to compute the value on load, but I am guessing that it didn't work because my (and the rowData) view is not available on load. That would eventually present a problem when I wanted to use partial refreshes due to updates on the criteria for which fields I want to display anyway.
Some of the answers to other questions looked promising, but no code was provided, so I couldn't figure it out.
Behind the scenes, all data sources use the methods getValue and setValue to (respectively) read and write data. In the case of a Domino document data source, the expression #{currentDocument.fieldName} gets translated at runtime to either currentDocument.getValue('fieldName') or currentDocument.setValue('fieldName', postedValue), depending on whether the current operation is a read or a write.
If you set the value attribute of an otherwise editable component to a SSJS value binding, then it can't do this auto-translation... so it just treats every operation as a read.
In other words, for read/write to work, it has to be a "prefixless" expression.
There are several ways to handle this, but the easiest is to use a data context to map a SSJS expression to a single variable. Data contexts can be attached to the view root or to a panel, so in your example, you'd want to wrap your repeat contents in a panel:
<xp:repeat id="repeat2" rows="30" var="rowData" style="width:700px"
value="#{competitionQuestionView}">
<xp:panel>
<xp:this.dataContexts>
<xp:dataContext var="fieldName">
<xp:this.value><![CDATA[#{javascript:rowData.getColumnValue ("FieldName");}]]></xp:this.value>
</xp:dataContext>
</xp:this.dataContexts>
<xp:label id="label1">
<xp:this.value><![CDATA[#{javascript:rowData.getColumnValue("Question");}]]> </xp:this.value>
</xp:label>
<xp:inputText id="inputText1" value="#{poDoc[fieldName]}">
<xp:this.rendered><![CDATA[#{javascript:rowData.getColumnValue("FieldType") == "Text Box"; }]]></xp:this.rendered>
</xp:inputText>
</xp:panel>
</xp:repeat>
So for each member of the repeat, the variable fieldName becomes the column value for that row. Then in the value attribute of the input component, the array syntax is used (instead of the usual dot syntax) since we want to use a variable to specify the field name instead of hardcoding the name.
In theory, however, you should be able to skip the data context entirely, and just set the following to be the value expression for the field:
#{poDoc[rowData.FieldName]}
In the context of the default ("prefixless") EL resolver, rowData.FieldName should return precisely the same value that rowData.getColumnValue("FieldName") returns in the context of a SSJS expression.
Finally, I would recommend reading this Expression Language tutorial to become familiar with all of the things that you can do in core EL without resorting to SSJS.

Resources