Extjs bind fromDate and ToDate in Calendar date picker











up vote
0
down vote

favorite












I want 2 conditions using bind:




  1. toDate should not be less than fromdate

  2. to date should not be more than (fromdate+ 1 year) i.e maxvalue = fromdate+1 year


This is the code:



        var me = this;
return [ {
xtype : 'form',
layout : 'hbox',
border : false,
items : [ {
xtype : 'datefield',
name : 'fromDate',
// allowBlank : false,
width : 110,
fieldLabel : 'From',
labelAlign : 'top',
emptyText : 'mm/dd/yyyy',
submitEmptyText : false,
invalidText : '{0} is not a valid date!',
fieldStyle : "font: bold 12px sans-serif;background:#fff;color:#444;",
padding : 5,
validator: function(value) {
if(value){
if(new Date(value) > new Date){
return 'From date must be less than current date.';
}else
return true;
} else {
return 'From date is required.';
}
var isRequired = me.oneFieldRequired();
if(typeof isRequired === "string")
return isRequired;
return me.validateName(value);
}
}, {
xtype : 'datefield',
name : 'toDate',
width : 110,
fieldLabel : 'To',
labelAlign : 'top',
emptyText : 'mm/dd/yyyy',
invalidText : '{0} is not a valid date!',
fieldStyle : "font: bold 12px sans-serif;background:#fff;color:#444;",
padding : 5
}, {
xtype : 'button',
padding : '4 8',
margin : '30 0 0 3',
text : 'Go',
handler : function(btn) {
var thisForm = btn.up('form').getForm();
var formValues = thisForm.getValues();
if(!thisForm.findField("fromDate").validate())
return;

var toDate = formValues.toDate ? new Date(formValues.toDate) : new Date(),
t = toDate.getTime() - new Date(formValues.fromDate).getTime(),
cm = 24 * 60 * 60 * 1000 * 30,
monthRange = Math.floor(t / cm);
if(monthRange >= 0){
var ToDate = toDate;
if(monthRange > 11){
var fd = new Date(formValues.fromDate);
fd.setMonth(fd.getMonth()+11);
ToDate = new Date(fd.getFullYear(),fd.getMonth() + 1, 0);
}
ToDate = (ToDate.getMonth() + 1) + "/" + ToDate.getDate() + "/" + ToDate.getFullYear();
Ext.StoreManager.lookup('Visits').eAjax({
empiRefId : PatientManager.getPatientId(),
fromDate : formValues.fromDate,
toDate : ToDate,
preference : {
enableVisitTypeFilter : true,
outputType : 'highLevel'
}
}, this, {
success : function(records) {
me.showCustomView(records, formValues.fromDate, ToDate);
},
failure : function(response) {},
empty : function(response) {
me.showCustomView(, formValues.fromDate, ToDate);
}

});
btn.up('tooltip').close();
}
}
} ]
} ];









share|improve this question




























    up vote
    0
    down vote

    favorite












    I want 2 conditions using bind:




    1. toDate should not be less than fromdate

    2. to date should not be more than (fromdate+ 1 year) i.e maxvalue = fromdate+1 year


    This is the code:



            var me = this;
    return [ {
    xtype : 'form',
    layout : 'hbox',
    border : false,
    items : [ {
    xtype : 'datefield',
    name : 'fromDate',
    // allowBlank : false,
    width : 110,
    fieldLabel : 'From',
    labelAlign : 'top',
    emptyText : 'mm/dd/yyyy',
    submitEmptyText : false,
    invalidText : '{0} is not a valid date!',
    fieldStyle : "font: bold 12px sans-serif;background:#fff;color:#444;",
    padding : 5,
    validator: function(value) {
    if(value){
    if(new Date(value) > new Date){
    return 'From date must be less than current date.';
    }else
    return true;
    } else {
    return 'From date is required.';
    }
    var isRequired = me.oneFieldRequired();
    if(typeof isRequired === "string")
    return isRequired;
    return me.validateName(value);
    }
    }, {
    xtype : 'datefield',
    name : 'toDate',
    width : 110,
    fieldLabel : 'To',
    labelAlign : 'top',
    emptyText : 'mm/dd/yyyy',
    invalidText : '{0} is not a valid date!',
    fieldStyle : "font: bold 12px sans-serif;background:#fff;color:#444;",
    padding : 5
    }, {
    xtype : 'button',
    padding : '4 8',
    margin : '30 0 0 3',
    text : 'Go',
    handler : function(btn) {
    var thisForm = btn.up('form').getForm();
    var formValues = thisForm.getValues();
    if(!thisForm.findField("fromDate").validate())
    return;

    var toDate = formValues.toDate ? new Date(formValues.toDate) : new Date(),
    t = toDate.getTime() - new Date(formValues.fromDate).getTime(),
    cm = 24 * 60 * 60 * 1000 * 30,
    monthRange = Math.floor(t / cm);
    if(monthRange >= 0){
    var ToDate = toDate;
    if(monthRange > 11){
    var fd = new Date(formValues.fromDate);
    fd.setMonth(fd.getMonth()+11);
    ToDate = new Date(fd.getFullYear(),fd.getMonth() + 1, 0);
    }
    ToDate = (ToDate.getMonth() + 1) + "/" + ToDate.getDate() + "/" + ToDate.getFullYear();
    Ext.StoreManager.lookup('Visits').eAjax({
    empiRefId : PatientManager.getPatientId(),
    fromDate : formValues.fromDate,
    toDate : ToDate,
    preference : {
    enableVisitTypeFilter : true,
    outputType : 'highLevel'
    }
    }, this, {
    success : function(records) {
    me.showCustomView(records, formValues.fromDate, ToDate);
    },
    failure : function(response) {},
    empty : function(response) {
    me.showCustomView(, formValues.fromDate, ToDate);
    }

    });
    btn.up('tooltip').close();
    }
    }
    } ]
    } ];









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I want 2 conditions using bind:




      1. toDate should not be less than fromdate

      2. to date should not be more than (fromdate+ 1 year) i.e maxvalue = fromdate+1 year


      This is the code:



              var me = this;
      return [ {
      xtype : 'form',
      layout : 'hbox',
      border : false,
      items : [ {
      xtype : 'datefield',
      name : 'fromDate',
      // allowBlank : false,
      width : 110,
      fieldLabel : 'From',
      labelAlign : 'top',
      emptyText : 'mm/dd/yyyy',
      submitEmptyText : false,
      invalidText : '{0} is not a valid date!',
      fieldStyle : "font: bold 12px sans-serif;background:#fff;color:#444;",
      padding : 5,
      validator: function(value) {
      if(value){
      if(new Date(value) > new Date){
      return 'From date must be less than current date.';
      }else
      return true;
      } else {
      return 'From date is required.';
      }
      var isRequired = me.oneFieldRequired();
      if(typeof isRequired === "string")
      return isRequired;
      return me.validateName(value);
      }
      }, {
      xtype : 'datefield',
      name : 'toDate',
      width : 110,
      fieldLabel : 'To',
      labelAlign : 'top',
      emptyText : 'mm/dd/yyyy',
      invalidText : '{0} is not a valid date!',
      fieldStyle : "font: bold 12px sans-serif;background:#fff;color:#444;",
      padding : 5
      }, {
      xtype : 'button',
      padding : '4 8',
      margin : '30 0 0 3',
      text : 'Go',
      handler : function(btn) {
      var thisForm = btn.up('form').getForm();
      var formValues = thisForm.getValues();
      if(!thisForm.findField("fromDate").validate())
      return;

      var toDate = formValues.toDate ? new Date(formValues.toDate) : new Date(),
      t = toDate.getTime() - new Date(formValues.fromDate).getTime(),
      cm = 24 * 60 * 60 * 1000 * 30,
      monthRange = Math.floor(t / cm);
      if(monthRange >= 0){
      var ToDate = toDate;
      if(monthRange > 11){
      var fd = new Date(formValues.fromDate);
      fd.setMonth(fd.getMonth()+11);
      ToDate = new Date(fd.getFullYear(),fd.getMonth() + 1, 0);
      }
      ToDate = (ToDate.getMonth() + 1) + "/" + ToDate.getDate() + "/" + ToDate.getFullYear();
      Ext.StoreManager.lookup('Visits').eAjax({
      empiRefId : PatientManager.getPatientId(),
      fromDate : formValues.fromDate,
      toDate : ToDate,
      preference : {
      enableVisitTypeFilter : true,
      outputType : 'highLevel'
      }
      }, this, {
      success : function(records) {
      me.showCustomView(records, formValues.fromDate, ToDate);
      },
      failure : function(response) {},
      empty : function(response) {
      me.showCustomView(, formValues.fromDate, ToDate);
      }

      });
      btn.up('tooltip').close();
      }
      }
      } ]
      } ];









      share|improve this question















      I want 2 conditions using bind:




      1. toDate should not be less than fromdate

      2. to date should not be more than (fromdate+ 1 year) i.e maxvalue = fromdate+1 year


      This is the code:



              var me = this;
      return [ {
      xtype : 'form',
      layout : 'hbox',
      border : false,
      items : [ {
      xtype : 'datefield',
      name : 'fromDate',
      // allowBlank : false,
      width : 110,
      fieldLabel : 'From',
      labelAlign : 'top',
      emptyText : 'mm/dd/yyyy',
      submitEmptyText : false,
      invalidText : '{0} is not a valid date!',
      fieldStyle : "font: bold 12px sans-serif;background:#fff;color:#444;",
      padding : 5,
      validator: function(value) {
      if(value){
      if(new Date(value) > new Date){
      return 'From date must be less than current date.';
      }else
      return true;
      } else {
      return 'From date is required.';
      }
      var isRequired = me.oneFieldRequired();
      if(typeof isRequired === "string")
      return isRequired;
      return me.validateName(value);
      }
      }, {
      xtype : 'datefield',
      name : 'toDate',
      width : 110,
      fieldLabel : 'To',
      labelAlign : 'top',
      emptyText : 'mm/dd/yyyy',
      invalidText : '{0} is not a valid date!',
      fieldStyle : "font: bold 12px sans-serif;background:#fff;color:#444;",
      padding : 5
      }, {
      xtype : 'button',
      padding : '4 8',
      margin : '30 0 0 3',
      text : 'Go',
      handler : function(btn) {
      var thisForm = btn.up('form').getForm();
      var formValues = thisForm.getValues();
      if(!thisForm.findField("fromDate").validate())
      return;

      var toDate = formValues.toDate ? new Date(formValues.toDate) : new Date(),
      t = toDate.getTime() - new Date(formValues.fromDate).getTime(),
      cm = 24 * 60 * 60 * 1000 * 30,
      monthRange = Math.floor(t / cm);
      if(monthRange >= 0){
      var ToDate = toDate;
      if(monthRange > 11){
      var fd = new Date(formValues.fromDate);
      fd.setMonth(fd.getMonth()+11);
      ToDate = new Date(fd.getFullYear(),fd.getMonth() + 1, 0);
      }
      ToDate = (ToDate.getMonth() + 1) + "/" + ToDate.getDate() + "/" + ToDate.getFullYear();
      Ext.StoreManager.lookup('Visits').eAjax({
      empiRefId : PatientManager.getPatientId(),
      fromDate : formValues.fromDate,
      toDate : ToDate,
      preference : {
      enableVisitTypeFilter : true,
      outputType : 'highLevel'
      }
      }, this, {
      success : function(records) {
      me.showCustomView(records, formValues.fromDate, ToDate);
      },
      failure : function(response) {},
      empty : function(response) {
      me.showCustomView(, formValues.fromDate, ToDate);
      }

      });
      btn.up('tooltip').close();
      }
      }
      } ]
      } ];






      javascript extjs extjs5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 at 6:40









      Zhorov

      2,7892515




      2,7892515










      asked Nov 22 at 5:21









      Shivangi Joshi

      13




      13





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424341%2fextjs-bind-fromdate-and-todate-in-calendar-date-picker%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424341%2fextjs-bind-fromdate-and-todate-in-calendar-date-picker%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Basket-ball féminin

          Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

          I want to find a topological embedding $f : X rightarrow Y$ and $g: Y rightarrow X$, yet $X$ is not...