Vue datepicker change value to string - date

I use vuejs-datepicker. I try add to value string, but input is empty, I can only add date:
<datepicker :value="getDateDB"></datepicker>
getDateDB(){
if (getDate == 'no_date') {
return 'No date';
} else {
return new Date(date);
}
}
I found this description in documencation vuejs-datepicker:
Prop Type Description
value Date|String Date value of the datepicker
How I can add to :value string ?

the datepicker is ok, you problem should be in your method, make the method computed if is not and the variable getDate maybe is 'undefined', maybe should be this.getDate

Related

How to compare Date in criteriaBuilder.greaterThan()?

I'm fixing a bug in JAVA/Angular Project, I'm getting a Date in Millisecodes from the front End, then I change the date from Millisecondes to "yyyy MM dd HH:mm:ss" format using SimpleDateFormat class in JAVA.
I want to compare the date that I'm getting from the front end with a field in a Table in my DataBase using criteriaBuilder.greaterThan().
The type of the field is bigInit(20).
I proposed as a solution to compare the dates using TimesTamp type, but the request from the client is a comparaison using Date in JAVA
public Specification<T> greater(Object value, String field, String type) {
return (root, criteriaQuery, criteriaBuilder) -> {
Path tuple = getPath(root, field);
System.out.println("type" + tuple.getJavaType());
if (tuple.getJavaType().isAssignableFrom(Date.class)) {
return criteriaBuilder.greaterThan(tuple, convertFilterDateToDate(value.toString()));
}
return criteriaBuilder.greaterThan(getPath(root,field),Double.valueOf(value.toString()));
};
}
This method takes 3 parametrs :
Object value : its type is Long in my case, it is the value of the date taken from the front End, I wrote a method to convert the value from Long to Date using SimpleDateFormat.
String field: its the field in my table, it contains dates with type Long.
String Type: it contains the value 'endDate' in my case.
Below, the definition of getPath Method :
public Path getPath(Root<T> root, String field){
String fiedls[] = field.split("\\.");
if(!field.contains(".")){
System.out.print(root.get(field));
return root.get(field);
}
else if (fiedls.length==2){
Join<Operation,Object> join = root.join(fiedls[0]);
return join.get(fiedls[1]);
}
else if(fiedls.length==3){
Join<Operation,Object> join = root.join(fiedls[0]);
Join<Object,Object> join1 = join.join(fiedls[1]);
return join1.get(fiedls[2]);
}
return null;
}
The request is to compare date using Date type in java and criteriaBuilder.greaterThan() , any Idea ?

Value of text field in protractor- undefined

I am not able to get value of label (as value is not editable and return by API).
I am using getText, but out put is always undefined. The value of this field is 2222.
using below
var activatedid = element(By.xpath("/html/body/app-root/mat-toolbar/div[3]/div[3]"));
activatedid.getText()
.then(function(text) {
console.log(this.text);
Remove this. before text, so you have
var activatedid = element(By.xpath("/html/body/app-root/mat-toolbar/div[3]/div[3]"));
activatedid.getText()
.then(function(text) {
console.log(text);
})

Why is the datepicker not recognizing wrong format?

I have a datepicker that was created with the following code snippet:
return new sap.m.DatePicker(sId, {
dateValue: `{${sPath}}`,
valueFormat: "dd-MM-yyyy",
displayFormat: "dd-MM-yyyy"
});
Typing wrong weird stuff into the field:
It does not recognize the invalid format.
But when I tried to write in this example, it does recognize.
What am I doing wrong?
const oDatePicker = new DatePicker(sId).bindValue({
path: sPath,
type: new DateType({ // "sap/ui/model/type/Date"
pattern: "dd-MM-yyyy",
})
});
const messageManager = sap.ui.getCore().getMessageManager();
messageManager.registerObject(oDatePicker, true);
return oDataPicker;
If working with data binding, you'll need to bind the value property instead of dateValue.
API reference: sap.m.DatePicker
Use the value property if you want to bind the DatePicker to a model using the sap.ui.model.type.Date.
Use the dateValue property if the date is already provided as a JavaScript Date object or you want to work with a JavaScript Date object. (...) Although possible to bind it, the recommendation is not to do it. When binding is needed, use value property instead.
And finally, register the control to the MessageManager or enable handleValidation. UI5 will then take care of displaying the error message if the input could not be parsed or violates given constraints.
https://sapui5.hana.ondemand.com/#/sample/sap.m.sample.DatePicker/code/Group.controller.js
handleChange: function (oEvent) {
var oText = this.byId("T1");
var oDP = oEvent.oSource;
var sValue = oEvent.getParameter("value");
var bValid = oEvent.getParameter("valid");
this._iEvent++;
oText.setText("Change - Event " + this._iEvent + ": DatePicker " + oDP.getId() + ":" + sValue);
if (bValid) {
oDP.setValueState(sap.ui.core.ValueState.None);
} else {
oDP.setValueState(sap.ui.core.ValueState.Error);
}
}
this is the change handler used in the sample you have to implement the error handling by yourself

How to get and set Real value from RealEdit in a Form's Grid ?

I have in a Grid a RealEdit , I set the autodeclaration YES.
The name is myRealEdit , DataSource is myTable and the Field is myRealField.
In the modified method I want to get the value, I need to do a IF control.
IF the value is 0 change the Filed's value IF the value is not 0
throws the value entered and restores the previous value.
I used this code, in modified method:
public boolean modified()
{
boolean ret;
real storedValue;
ret = super();
storedValue = myTable.myRealField; // there is another way to get the value ?
if (myRealEdit.valueStr() == "0")
//accept the value
if (!myRealEdit.valueStr() != "0")
{
myRealEdit.realValue(storedValue);
}
return ret;
}
If the value is not 0 (zero) don't restore the previous value.
I have to use another method ? There is another way to get the real value ?
Thanks in advice,
enjoy!!
Since you are using the modified method in your answer, I suppose you want to put this field validation on the control level (instead of the datasource or table level).
As #Jan B. Kjeldsen suggested in his comment, you should use the validate method to do this validation. Use the modified method only if you want to add some logic that is executed in addition to the field value modification.
The validate method could look similar to
public boolean validate()
{
return this.realValue() == 0 && super() || checkFailed(strFmt("Value %1 is not permitted", this.realValue()));
// TODO please replace this with a Label and explain to the user why the value is not permitted and what he or she can do to resolve this
}
I find a possible way,
I used this code:
public boolean modified()
{
boolean ret;
if (myRealEdit.valueStr() == "0")
{
//accept the value
ret = super();
}
if (!myRealEdit.valueStr() != "0")
{
info("Value not permit");
// nothing to do
}
return ret;
}
In this way, if and only if I have a value 0 I modified the value.
I need to get or read the Real value just inserted from myRealEdit in the modified method.
If the community has comments or improvements inserted, will be more information.

How can the ToDate be kept after the FromDate in a table record?

I have a table with two fields: FromDate and ToDate. I want to make sure that the ToDate value is always later than the FromDate value.
To do this, I want to set the ToDate value to the FromDate value + 1. To do this I have implemented the following code in the validateField method of the table:
boolean ret;
ret = super(_fieldIdToCheck);
if (ret)
{
switch (_fieldIdToCheck)
{
case fieldNum(MyTable, FromDate):
this.ToDate = this.FromDate + 1;
}
}
return ret;
This implementation works well, but the value of ToDate can be changed to a value before FromDate. How can this be prevented?
As Alex said, use the table method modifiedField to do field dependant modifications.
If you change the field by code remember to call the method yourself.
Maybe you should make the assignment conditional to avoid overwriting user entered date. This will also work well if ToDate is initially null.
public void modifiedField(FieldId _fieldId)
{
super(_fieldId);
switch(_fieldId)
{
case fieldNum(MyTable, FromDate):
case fieldNum(MyTable, ToDate):
if (this.ToDate < this.FromDate) // mostly first time
this.ToDate = this.FromDate + 1;
break; // don't forget the break
}
}