cancel
Showing results for 
Search instead for 
Did you mean: 

Biding datePicker

0 Kudos

I'v got 2 date picker's in my project and I want to change one datePicker and change the other.

For some reason when I change one the other one didn't change.

Can you please help?!

This the one I attach an event -

<DatePicker id="docDueDeteId" width="10rem" change="onChangeNecessidadeGeral">
<layoutData>
<OverflowToolbarLayoutData priority="NeverOverflow"/>
</layoutData>
</DatePicker>

This is the one It will change after I change the first one:

<t:Column width="9rem" id="colDateId">
<Label text="Necessidade"/>
<t:template>
<DatePicker id="colDateId1" dateValue="{jModel>necessidade}"/>
</t:template>
</t:Column>

In the controller:

onChangeNecessidadeGeral: function (oEvent) {
var data = oEvent.getSource().getDateValue();
var typeRequest = this.getView().byId("typeRequestId").getText();
var that = this;
var txtWarning = "Do you want to change in the other date fields?";
MessageBox.warning(txtWarning, {
actions: [MessageBox.Action.OK, MessageBox.Action.CANCEL],
emphasizedAction: MessageBox.Action.OK,
onClose: function (sAction) {
if (sAction !== "CANCEL") {
that.changeNecessidade(data, typeRequest);
}
}
});
},
changeNecessidade: function (data, typeRequest) {
var oView = this.getView();
if (typeRequest === "Artigo") {
oView.byId("colDateId1").setDateValue(data); 
} else if (typeRequest === "Serviço") {
oView.byId("colNecessidadeId1").setDateValue(data);
}
}

Accepted Solutions (1)

Accepted Solutions (1)

priteshpatel65
Active Participant

hi, this code work fine but your second datepicker is in table so you need to check this.getView().byId("typeRequestId").getText(); its proper work or not and other way is using formatter

hope it helped you

onChangeNecessidadeGeral: function (oEvent) {
debugger;
var data = oEvent.getSource().getDateValue();
var typeRequest = "demo";
var that = this;
var txtWarning = "Do you want to change in the other date fields?";
sap.m.MessageBox.success(txtWarning, {
actions: [sap.m.MessageBox.Action.OK, sap.m.MessageBox.Action.CANCEL],
emphasizedAction: sap.m.MessageBox.Action.OK,
onClose: function (sAction) {
if (sAction !== "CANCEL") {
that.changeNecessidade(data, typeRequest);
}
}
});
},
changeNecessidade: function (data, typeRequest) {
var that = this;
if (typeRequest === "demo") {
that.byId("colDateId1").setDateValue(data);
}
}

Answers (2)

Answers (2)

former_member450774
Participant

Hi,

What is the error message you are getting..

Hope the conditions on typeRequest are not satisfying.

Below is the quick example for your reference.

View:

<DatePicker id="DP1" placeholder="Enter Date 1" change="handleChange1"/>
<DatePicker id="DP2" placeholder="Enter Date 2" change="handleChange2"/>

controller:

handleChange1: function(oEvent) 
{
var sDate1 = oEvent.getSource().getDateValue();
this.getView().byId("DP2").setDateValue(sDate1);
},

handleChange2: function(oEvent) 
{
var sDate2 = oEvent.getSource().getDateValue();
this.getView().byId("DP1").setDateValue(sDate2 );
},

Hope it helped you!

Rajesh.

0 Kudos

Thank you for your aswers.

I didn't explained myself properly.

One of the <datePicker>'s is inside a grid table who is fulfill by a jsonModel.

I found the solution, just changed the value of the property in the model and the value of the datePicker inside the table change.

onChange: function (data, typeRequest) {
    var myData = this.jModel.getProperty("/requestSpecific"),
        oDataLength = myData.length,
        oModel = this.jModel,
        i;
    for (i = 0; i < oDataLength; i++) {
        oModel.setProperty("/requestSpecific/" + i + "/necessidade", data);
    }
},