I have a few problems with regards to dateFormatter and inputFormat. We have overwritten these two properties and provided our own implementation. Our logic includes custom formatting as well as validation. We have a validation flag on the element that we maintain called "$cwInvalid". This is originally set in the inputFormat function. When dateFormatter is called, it checks if this flag is set and if the date object coming in is invalid (because changing the value from the picker doesn't call inputFormat, therefore we would not have set the flag), return the last known string value (we want to keep the invalid value on the screen). If it is not currently set, then we format it and return the display string.
My problem right now is that dateFormatter is not only called to format the value coming in, it is also called to format the previous value to check if the value has changed which messes up our validation flag logic. The validation flag is wiped out because a previous value is valid.
This is the same issue in inputFormat because it is not only called when the user inputs some values, it is also called for formatting the startDate. when startDate comes in, my validation flag is wiped out because it is a valid value and I have no idea that it is in fact just for the startDate and not for the actual value.
What I would like to know is if there is any way around this? Can I somehow detect where the value is coming from? The key things I want to achieve:
- when the user has entered an invalid value, I want that invalid value to stay on the screen.
- when the user has entered a valid value, I want the valid value to appear and be saved on the date element.
- when the user enters and invalid value then a valid value, I want the valid value to be saved.
- when the user enters a valid value then an invalid value, I want the invalid value to stay on the screen.
- i don't care about formatting the old value OR the startDate
Below is a VERY rough idea of what we have but with hard-coded values- our formatting logic is in GWT's java code so I could not add it in. I hope it is somewhat clear - please let me know if there is some clarification needed.
To run the testcase, input the string "11" in the date textfield and focus out of the date element. At this point, our flag $cwIsValid is set to true and the date element has an invalid date object as its value. Now click on the picker icon and select a date. The displayFormat function will be called with the new AND the old invalid value.
My problem right now is that dateFormatter is not only called to format the value coming in, it is also called to format the previous value to check if the value has changed which messes up our validation flag logic. The validation flag is wiped out because a previous value is valid.
This is the same issue in inputFormat because it is not only called when the user inputs some values, it is also called for formatting the startDate. when startDate comes in, my validation flag is wiped out because it is a valid value and I have no idea that it is in fact just for the startDate and not for the actual value.
What I would like to know is if there is any way around this? Can I somehow detect where the value is coming from? The key things I want to achieve:
- when the user has entered an invalid value, I want that invalid value to stay on the screen.
- when the user has entered a valid value, I want the valid value to appear and be saved on the date element.
- when the user enters and invalid value then a valid value, I want the valid value to be saved.
- when the user enters a valid value then an invalid value, I want the invalid value to stay on the screen.
- i don't care about formatting the old value OR the startDate
Below is a VERY rough idea of what we have but with hard-coded values- our formatting logic is in GWT's java code so I could not add it in. I hope it is somewhat clear - please let me know if there is some clarification needed.
To run the testcase, input the string "11" in the date textfield and focus out of the date element. At this point, our flag $cwIsValid is set to true and the date element has an invalid date object as its value. Now click on the picker icon and select a date. The displayFormat function will be called with the new AND the old invalid value.
Code:
<HTML><HEAD><TITLE>Copy-Paste Issue</TITLE> </HEAD> <body class="pageBackground" marginwidth="0" marginheight="0" topmargin="0" leftmargin="0" scroll="no" style="overflow:hidden"> <SCRIPT>var isomorphicDir = "isomorphic/"</SCRIPT> <SCRIPT>var isomorphicDir = "isomorphic/"</SCRIPT> <SCRIPT SRC=isomorphic/system/modules/ISC_Core.js></SCRIPT> <SCRIPT SRC=isomorphic/system/modules/ISC_Foundation.js></SCRIPT> <SCRIPT SRC=isomorphic/system/modules/ISC_Containers.js></SCRIPT> <SCRIPT SRC=isomorphic/system/modules/ISC_Grids.js></SCRIPT> <SCRIPT SRC=isomorphic/system/modules/ISC_Forms.js></SCRIPT> <SCRIPT SRC=isomorphic/system/modules/ISC_DataBinding.js></SCRIPT> <SCRIPT SRC=isomorphic/skins/Enterprise/load_skin.js></SCRIPT> <SCRIPT> window.convertDateFormat= function(value,element){ isc.Log.logWarn(" convertDateFormat: being called with value : " +value); if(element.$cwInvalid){ isc.Log.logWarn(" convertDateFormat: current value is invalid, returning: " +element.cwCurrentStringFormat); return element.cwCurrentStringFormat; } var newDateFormat = value.getTime() == -1?"12/31/1969":"06/05/2011"; //if formatting this date value has failed, return the current string value that caused the error in the first place if(value.getTime()=="-1"){ return "-1"; }else{ element.$cwInvalid = null; isc.Log.logWarn(" convertDateFormat: current value is 'valid', returning: " +newDateFormat); return newDateFormat; } }; window.convertInputToDate = function(string, element){ var newDate = window.Date.create(); var isValue = false; isc.Log.logWarn(" convertInputFormat: being called with value : " +string); if(element.textField!=null && element.textField.getValue() == string){ isValue = true; } element.cwCurrentStringFormat = string; if(string == "11"){ isc.Log.logWarn(" convertInputFormat: called with invalid value"); newDate.setTime(-1); element.$cwInvalid = true; }else if(isValue){ isc.Log.logWarn(" convertInputFormat: erasing invalidvalue flag"); element.$cwInvalid = null; } return newDate; }; isc.setAutoDraw(false); isc.VStack.create({ ID:"LoginGrid_vCentering", name:"LoginGrid_vCentering", autoDraw:true, height:"100%",width:"100%", align:"center", defaultLayoutAlign:"center", members: [isc.DynamicForm.create({ ID:"LoginGrid", name:"LoginGrid", numCols:3, colWidths:["144","288","144"], titleOrientation:"left", margin:0, fields: [{title:"Date Issue", name:"dateissue", _constructor:"DateItem", useTextField:true, startDate:"01\/01\/1995", init: function(){ var dateItem = this; this.dateFormatter = function(){return window.convertDateFormat(this,dateItem);}; this.inputFormat = function(string){return window.convertInputToDate(string,dateItem);}; this.Super("init"); } }, {type:"text",name:"dummy"} ]})]}); </script> </BODY> </html>
Comment