Form datetime type validation error - symfony-2.1

I'm using collection form type, where children has datetime type input as single text. But when I submit data in validation fails and getErrorsAsString shows this strange error:
inputDateTime:
ERROR: This value is not valid.
date:
No errors
time:
No errors
Here is how I add my field
//form child
$builder->add('inputDateTime', 'datetime', array(
'date_widget' => 'single_text',
'time_widget' => 'single_text'
));
Why inputDateTime has errors but neither date or time has errors? My locale is set and I tried to add date format but it didn't help.

The "error_bubbling" property of the "date" and the "time" field is set to true, thus errors on those fields bubble up and are attached to the datetime field instead.
You are right that the error message is not very helpful (there's an open ticket for that) but you can debug the problem by printing the $exception variable in the block that catches the TransformationFailedException generated by the DataTransformer (Form.php:611). The exception contains the detailed error description, which is hidden from the end user for security purposes.

In fact it appears that is due to an invalid format date (when you are using a different format which can appears when you have set another timezone or locale for instance). As a result, you juste have to specify the date_format options for the datetime field.
In my case, this solve the issue :
'date_format' => 'dd/MM/yyyy',

Related

How can i compare two times using joi library

I have two times fields. I need to apply validation using joi library,
Currently i have applied a validation it is showing error as :
TypeError: joi.string(...).required(...).less is not a function.
The validation is Planned Start time should be less than Planned End time. !
I have done the following code:
{
schema=joi.object({
taskname:joi.string().required().label('Please enter Task Description!'),
task:joi.string().invalid(' ').required().label('Please enter Task Description!'),
taskn:joi.string().min(1).max(80).required().label(' Task Description too long.'),
projectname:joi.string().required().label('Please select Project !'),
type:joi.string().required().label('Please select Task Type !'),
status:joi.string().invalid('None').required().label('Please choose Status'),
plannedstarttime:joi.string().regex(/^([0-9]{2})\:([0-9]{2})$/).required().label('Please fill Planned Start Time !'),
plannedendtime:joi.string().regex(/^([0-9]{2})\:([0-9]{2})$/).required().label('Please fill Planned
End Time !'),
plantime:joi.string().required().less(joi.ref('plannedendtime')).label('Planned Start time should
be less than Planned End time. !'),
})
result=schema.validate({taskname:taskname,task:taskname,taskn:taskname,type:tasktype,projectname:projectname,status:request.body.status,plannedstarttime:plannedstarttime,plannedendtime:plannedendtime,plantime:plannedstarttime});
}
How can i achieve this validation.
You need to make sure you're working with the correct types. string doesn't define a less method, thus you get an error.
You can remove plantime, and provide a custom validation function, that implements a string comparison:
schema = joi.object({
...
// plantime: // <-- remove it
...
}).custom((doc, helpers) => {
if (doc.plannedstarttime > doc.plannedendtime) {
throw new Error("Planned Start time should be lower than Planned End time!");
}
return doc; // Return the value unchanged
});
Another option to consider is to work with a date type (BTW, don't you need to know the date as well, no just time?):
schema = joi.object({
...
plannedstarttime: joi.date().required() ...
plannedendtime: joi.date().required().greater(joi.ref('plannedstarttime')) ...
// plantime // <-- remove it
...
});
If you then want to format plannedstarttime and plannedendtime in a certain way, use format. The format should apply to moment.js formatting. For example, formatting to only show hour+minute is HH:mm.

PDFTron: What is the proper way to find date fields in a PDF form

[PdfTron 5.2]
I have a PDF form with text and date fields. I want to find the date fields.
I can get the actions of the field with getActions().
field.getActions()
returns
{"F":[{"yc":"JavaScript","Gt":"AFDate_FormatEx(\"dd.mm.yyyy\");"}],
"K":[{"yc":"JavaScript","Gt":"...);","ey":null}]}
As you can see, the date is in actions.F[0].Gt. But checking actions.F[0].Gt
for "AFDate" seems wrong, that's too low-level.
Is there a better API function to find out, that I have a date field?
Thank you.
You are correct. The Gt property is obfuscated and minified which is volatile and not meant to be used. If you require an API, you should refer to our documentation. Everything should be available there except a few (one of which will be used below), but feel free to contact us if you do need help!
Unfortunately, there is no API currently to get that type. From my limited understanding, the "type" of a field is determined by the attached actions and not simply a specific type or flag. This suggests all fields are just text fields with special formatting actions to make it look and feel like its a date or numeric field.
In this case, you will have to check the formatting action (F) as you have already noticed for the date formatting function (AFDate_FormatEx). To get the JavaScript from that action, you should use the javascript property on the action which was not in the documentation. However, you can see it if you console log the action.
Here is an example:
const dateActionJs = /.+:"AFDate_FormatEx\(.*/;
instance.docViewer.on('annotationsLoaded', () => {
const annotations = annotManager.getAnnotationsList();
annotations.forEach(annot => {
const actions = annot.getField().getActions();
if (actions.F && actions.F[0] && actions.F[0].javascript && dateActionJs.test(actions.F[0].javascript)) { // F = Format Action
console.log('Found Date');
}
});
});
Let me know if this helps!
EDIT: You can search for AFDate instead of AFDate_FormatEx which will be sufficient.

SuiteScript 2 can send pdf statements

I am having a hard time getting a statement to render in SS2, I had found an answer is SS1 and hadn't used it sometime back but it doesn't seem to work in ss2. I am using the SS2 render.statement method but I am getting an "error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"stack":["renderStatement(N/render.js)" I am unclear as to what some of the arguments actually are. the entityid I think is the customer id, the printMode is the pdf enum, the formId I have no idea, it says it wants a number but I don't see internal ids next to the forms in the list like other objects in NetSuite, I have the InternalIds on. StartDate is a date before you want to start pulling in transactions from? Statement date? Todays Date? OpentransactionOnly true. Any help with this is appreciated.
thanks
Many of the parameters in this API call mimic the UI options on the 'Print Individual Statement' page. I've copied some of the field level help there to help explain each setting.
entityId - internal ID of the customer. NOTE: I have had errors in the past which were solved by using parseInt(customer).
printMode - the print mode to render this statement in (eitherrender.PrintMode.HTML or render.PrintMode.PDF)
formId - internal ID of the form to use to print the statement. Leave this option off to use the default statement form.
startDate - If you choose to enter a date, this is the date of the oldest transaction that appears on the statement. If you choose to note enter a date, all transactions in the customer's history appear on the statement.
statementDate - Statement date. The date in this field is the date used to calculate aging and the date that appears on the statement form.
openTransactionsOnly - Select this option to include only open transactions on statements. If you have entered a start date, open transactions from that start date appear. If you have not entered a start date, all open transactions appear. The Show Only Open Transaction option is most useful for statements printed as of your current today date. If you select Show Only Open Transactions and are using a date other that today’s date, you may have balance discrepancies.
Here is an code snippet. It uses the moment.js for calculating the dates of the first and last day of the previous month.
var startDate = format.format({
value: moment().subtract(1, 'months').startOf('month').toDate(),
type: format.Type.DATE
});
var statementDate = format.format({
value: moment().subtract(1, 'months').endOf('month').toDate(),
type: format.Type.DATE
});
var statement = render.statement({
entityId: parseInt(customer),
printMode: render.PrintMode.PDF,
startDate: startDate,
statementDate: statementDate
});

Unable to render date from model template

I'm working on a Grails project with Freemarker and am having trouble rendering a date from the data model. I start put placing a date into the model
def dataModel = [:]
def dataDate = new Date().parse("yyyy-MM-dd","2015-08-20")
dataModel.put("someDate",dataDate)
I then loop through the dataModel to verify the data types
dataModel.each { name, value ->
println "${name} : ${value} (Value is type: ${value.getClass()})"
}
For this my output is: someDate : Thu Aug 20 00:00:00 CDT 2015 (Value is type: class java.util.Date)
Next I set up my confiuration and try to process the template
Configuration cfg = new Configuration(Configuration.VERSION_2_3_22)
cfg.setDefaultEncoding("UTF-8")
def ftlTemplate = new Template("name", new StringReader("${someDate}"), cfg)
Writer out = new StringWriter()
ftlTemplate.process(dataModel, out)
output = out.toString()
At this point I receive the following error
ERROR freemarker.runtime - Error executing FreeMarker template
Message: Can't convert the date-like value to string because it isn't known if it's a date (no time part), time or date-time value.
The blamed expression:
==> someDate [in template "name" at line 1, column 3]
I've found a Freemarker engine online here: http://freemarker-online.kenshoo.com/ and if I run the same datamodel and template through that the ouput I receive is: Aug 20, 2015
Can anyone point out where I am going wrong? I would like to render the output like that online engine does.
Thanks
The problem is (as the error message states) is that it's technically impossible to decide in general, if a java.util.Date stands for a date-only, date-time or time-only value. This is a technical fact that's outside FreeMarker. FreeMarker offers these ways to handle this problem:
Use ?date, ?time and ?datetime operators to give FreeMarker a hint in the template. See: http://freemarker.org/docs/ref_builtins_date.html#ref_builtin_date_datetype
Use java.sql.Date and java.sql.Timestamp and java.sql.Timestamp, where there's no such ambiguity. (Beware with Timestamp's funny fraction second handling though.)
Wrap the values manually into TemplateDateModel, where you can specify which kind of value it is. Then drop the TemplateDateModel into the data-model.
Change
new StringReader("${someDate}")
To
new StringReader('${someDate}')
The double quotes are probably causing double tempering
hi,look! you can try like these:
<td name="">${value.startTime?string('dd.MM.yyyy HH:mm:ss')}</td>
the you can replace value.startTime with the target varibale which is date or timestamp type

Get the date without the time of the selected value in rich:calendar

I got a problem when using rich:calendar: after selecting the value, I am setting the value in the bean of type Calendar. In the bean it is showing an error and the date value is appeared along with the time so how can we get only date value without getting the time
Here is the code I have written:
<rich:calendar value="#{editCustomerBean.person.demographic.dateOfBirth}"
cellWidth="15px" cellHeight="22px" style="width:200px"
datePattern="yyyy,dd,MM"/>
The error message says:
SEVERE: //C:/Workspace/Kumar/WebContent/satish/Main.xhtml #71,268
value="#{editCustomerBean.person.demographic.dateOfBirth}":
Can't set property 'dateOfBirth' on
class 'com.customer.types.Information' to value '7/11/12
12:00 AM'.
When I set the value 2012,11,07 in the main page, I get the value '7/11/12
12:00 AM' with an extra 12:00 AM.
How can I get only the date value?
The message you are seeing with the value '7/11/12 12:00 AM' is not wrong, it is just the result of the .toString() method of the object date create by rich:calendar.
You should check if the class com.customer.types.Information (which from the message, it seems that is the type of the editCustomerBean.person.demographic property) actually has the appropriate setDateOfBirth(Date dt) method. Then, fix your code accordingly (pointing to the proper property or creating the adequate setter).

Resources