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?
Related
I have added custom fields to the news item component in Sitefinity. I am using newsItem.GetValue(customFieldName) to get the value of the field name; however, this is proving to be an issue with translated pages. Is there a way that I can get this value via ID instead? Or how else cna I approach this?
If it is a field that can be translated, then you should use the GetString method instead of GetValue.
Also check this:
https://knowledgebase.progress.com/articles/Article/multilingual-getstring-method-does-not-fallback-for-text-field-values
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.
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.
I've got Form domain class and there is typeOfTransaction property. This property is required (blank: false). I want to write custom error message for this property, if the user does not set the value, the message must be appeared.
com.example.domain.form.typeOfTransaction.blank = Type of transaction required
Above is the message, but I don't get it when I'm trying to save form with empty typeOfTransaction field. Instead of this message I've got default message
"Please select an item in the list."
p.s. I don't know where this default message is defined.
If you use the absolute name of your class you need to use the exact name of the class, including capitalization - so I'm guessing you should put:
com.example.domain.Form.typeOfTransaction.blank = Type of transaction required
If you don't use the absolute name you don't capitalize the class name:
form.typeOfTransaction.blank = Type of transaction required
Well, for 1.3.7 it should be in grails-app/i18n/messages.properties (or one of the language specific variants if appropriate). I assume 2.0 would use the same location.