I'm trying to give some DateTime fields default values from the model browser.
Whatever I type into the Default Value field, I get an error telling me The value must be in the form 'yyyy-MM-dd HH:mm:ss.fffZ'. I am assuming that format string uses the scheme documented here.
The value I punched in is 2014-05-23 00:00:00.0000, which I believe is of that form. I'm not sure whether 0 is a valid value for the Z component, but I don't know what the right value would be.
What could be wrong with the string I gave?
I figured it out. The Z component was indeed the issue. I just needed to use 2014-05-23 00:00:00.000Z instead.
Related
I have an existing data model that has a unique indexed string field that defaults to an empty string.
I added an $attributes property to the model to default it to an empty string when creating a new object. That works just fine.
However when updating the object and the field remains empty, it will fail since the field is returned as null and the DB field is not nullable. I am not sure of the impact of making that field nullable(). Too much code to dig through so I can't change it.
I am thinking I can observe for an event, and change the value from null to empty string there, but I would rather take care of this in Nova.
Is there anyway to tell Nova an empty field should be saved as an empty string?
Short version: no.
Long version:
This cannot be set in Nova. An empty string will be passed as null in the HTTP request. This behaviour is part of Laravel's core. The only way to make sure it isn't passed as an empty string from Nova is to put form validation on it and make it a required field.
If you don't mind changing code on the Laravel app level, you can disable this behaviour by removing the ConvertEmptyStringsToNull middleware in your app's Kernel.
/app/Http/Kernel.php
protected $middleware = [
...
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, // remove this line
];
However, if the DB field isn't nullable, the field has to have a value anyway right? I'd suggest putting an accessor on the model to check for null values:
public function setMyFieldAttribute($val)
{
$this->attributes['my_field'] = $val ?? '';
}
Or, if you want to be really certain it always has a value, add an observer for the saving event (as you already mentioned), and make sure the field has a value before the data is actually saved.
I've an array of objects containing title and salary which is used in typeahead directive.
I display department name and get entire object as value.
If none of the options match, I want user entered string to be converted to object still. Is there any way to update that?
This answer is pretty late, but I would just use ng-blur (to trap the end of the users input) along with a variable bound to typeahead-no-results. Then test if the variable is true in the method bound to ng-blur, and, if so, make an object out of the String supplied by the user and push it to your data source. Simple example found here.
If I create a Domain Object with a nullable LocalDate, the scaffolding editor throws a validation error if the date is empty: Cant populate a class org.joda.time.LocalDate without a year
This seems to come from within the Joda DateTimeStructuredBindingEditor.getPropertyValue
Does anyone know how to prevent this validation problem?
I'm not positive, but if the issue is coming from the scaffolding, it's possible that it is sending a blank date, not a null one.
I would try to:
1 - Check if the localDate is actually null before you save it.
2 - Add "blank: true" as a constraint. You shouldn't need this, as it's not a string, but it may work.
http://grails.org/doc/latest/ref/Constraints/nullable.html
In my RazorView i use:
#Html.Editor(prop.PropertyName)
to get the EditorForm. It also creates the Tags: data-val-* with Validationmessages. But in this auto generated Validationmessages the variablename is shown as type.
data-val-number="The field "Int32" must be numeric."
I think this is because the object that cames to the Validationfunction misses the variablename and so he uses the type. So I need to know where the function tries to get the variablenname or which field the function tries to read to fix this.
p.s.
I realy donĀ“t want to change my previous code to fix this, it has his reasons why it is like it is ;-)
The variable name will default to the Property name unless you add a [DisplayName("New Name")] attribute to the Property to change the name used. What type is prop in your example?
By using g:datePicker on java.sql.Time object that refers to a TIME legacy DB column I get this error:
Failed to convert property value of type java.util.GregorianCalendar to required type java.sql.Time for property jobTime; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.util.GregorianCalendar] to required type [java.sql.Time] for property jobTime: PropertyEditor [org.codehaus.groovy.grails.web.binding.StructuredDateEditor] returned inappropriate value
I've searched through the whole web for hours but can't still figure out how to do, is there someone who can help please?
It looks like you're trying to convert a GregorianCalendar object to a Time object (at least, that's what the object says its doing). Try manually doing it:
// assuming that 'jobTime' is the object you're dealing with
jobTime = new java.sql.Time(jobTime.getTimeInMillis())
If you're absolutely sure its a Time object, try converting it to a Date object.
jobTime = new Date(jobTime.getTime())