Announcing the Global SNUG Board of Directors. Learn more here

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Need help with sp-date-picker directive

AK57
Kilo Explorer

Can someone please give an example on using the sp-date-picker directive with sn-include-time=true ?

I have tried to use it but the server script never catches the values from the html. How should the client controller look like in order to get this working ?

Thanks.

13 REPLIES 13

Raju Koyagura
Tera Guru

Try something like below...

HTML

<div>
<sp-date-picker field="data.datePicker" ng-model="data.datePicker" sn-change="customDate()" sn-include-time="true"></sp-date-picker>
</div>

 

Client Script:

 

function($scope) {
/* widget controller */
var c = this;
$scope.customDate = function () {
$scope.data.funcName="OnDate";
c.server.update().then(function(){})
};
}

Server Script:

(function() {
data.datePicker="";
if(input && input.funcName=="OnDate"){
gs.addInfoMessage(input.datePicker);
}
})();

Hi Raju,

Thanks for this - it's very handy. When I use your example, it works, except that the date is immediately cleared from the picker as soon as it's selected. How do we make it 'stick' so that it remains visible to the user?

Ah, I've realised, it sticks if I add a line to your server side script:

(function() {
 data.datePicker="";
 if(input && input.funcName=="OnDate"){
   data.datePicker = input.datePicker;
   gs.addInfoMessage(input.datePicker);
 }
})();

 

But this leads to another question, which is really about how the binding works: If we're setting the date with the picker, and we have this directive in our HTML: ng-model="data.datePicker", why does this not automatically set data.datePicker on the server side... or am I misunderstanding how binding works and it's always the case that we have set the server side value explicitly?

I've also realised, my additional line is not the best way to do this, as it seems to run the re-trigger the function from the HTML side, so I'm getting the infoMessage twice.