How can I add a default value to an editable date field bound to a datasource?

StackOverflow https://stackoverflow.com/questions/23349071

  •  11-07-2023
  •  | 
  •  

سؤال

I have created an Xpage with a form as the data source. It has 8 fields or so. One some of the fields I want to be able to set a default value (like today's date) but let the user change it.

I have an edit box bound to a date field on my form. If I put in a default value in the edit box control, it never appears unless I make the field read only.

I have tried adding the value in the before and after events.

Nothing works.

This has to be easy and I am overlooking something simple. Please help.

    var today = new Date();
    var dd = today.getDate();
    var mm = today.getMonth()+1; //January is 0!
    var yyyy = today.getFullYear();

    if(dd<10) {
        dd='0'+dd
    } 

    if(mm<10) {
        mm='0'+mm
    } 

    today = mm+'/'+dd+'/'+yyyy;
    var doc:NotesDocument = timeEntry.getDocument();

    //var thisDB:NotesDocument = session.getCurrentDatabase()
    //var document:NotesDocument = thisD

    if (doc.isNewNote()) {

      //doc.getComponent("date1").setValue(today);
      doc.replaceItemValue("date", today);
    }
هل كانت مفيدة؟

المحلول

Here's an example of an edit box control bound to a date field with a default value:

<xp:inputText id="Date" value="#{document.Date}" defaultValue="#{javascript:@Today()}">
    <xp:this.converter>
        <xp:convertDateTime type="date" />
    </xp:this.converter>
    <xp:dateTimeHelper id="dateTimeHelper2" />
</xp:inputText>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top