I have a transient attribute in my View Object and I want to make in a required field in the model layer. I do not want to use required property on view layer to true. I want my validation to be on the model layer. Is there a way to achieve this?
JDev version using: 11.1.17
In 11.1.1.7 Transient attributes cannot be marked "Mandatory." This is available in current release 12c.
Regardless, it's better to create a declarative validation that works against the attribute to evaluate it's size (chars or bytes) and then throw a validation error. See here and 7.4.10 How to Validate Against a Number of Bytes or Characters
Related
I'd like to add custom field types like 'email' or other strings that could use regex validation.
Also, numeric fields with validation like < or > or formatting like money.
I was thinking about storing a mapping of schema uuid + field name + field type, and have the UI query a new rest api to get the validation and formatting criteria when editing a node?
Does that sound like a good approach? or is there a better one?
I'm new to mesh, so I'm still learning how to approach customizations.
Thanks!
I think this relates to issue 112. At the moment it is not possible to add custom validation or custom field types. In the future more specific constraints can be added. Additionally we also plan to add a "control" property to schema fields. This field can be used to store any JSON. This JSON control property value can in turn be used in the UI to add custom form behavior or control how front-ends display/handle the value.
I am trying to change the metadata of fields of a object in salesforce using Apex. For example I am trying to make all required field non-required. I was able to retrieve all the required fields using the schema class and using methods like isNillable(). I wanted to ask if there is any way I can modify the metadata.
I have searched a lot regarding this but could not find any helpful results.
Schema.DescribeSObjectResult a_desc = objects.get(Name_of_of_object_whose_fields_are_to_be_retrieved).getDescribe();
Map<String, Schema.SObjectField> a_fields = a_desc.fields.getMap();
Set<string> x=a_fields.keySet();
//I am making a map of fieldname and bool(field required or not)
Map<String,boolean> result=new Map<String,boolean>();
for(String p:x)
result.put(p,a_fields.get(p).getDescribe().isCreateable() && !a_fields.get(p).getDescribe().isNillable() && !a_fields.get(p).getDescribe().isDefaultedOnCreate());
//what I want is to modify isNillable and other attributes and make these changes to the fields.
You can't make all required fields non-required because many of them are required at the database level and cannot be modified.
For example, the Name field (on any object that has a Name field) is always required. You cannot change this property. Likewise, Master-Detail relationship fields are always required, on standard and child objects.
To change the metadata of custom fields that are modifiable, you would have to use the Metadata API. It's not available in Apex, unless you use a wrapper like apex-mdapi. As a warning, modifying your org's metadata in a broad-based way via Apex is dangerous. You can cause damage to your org and its function in this way very easily. I strongly encourage you not to attempt to do this. Required fields are required for a reason.
So this is weird, wondering if perhaps SFDC is just returning "wrong" information.
I'm working with layouts for an object, and in the interface I have set a field in the default layout (there are no other layouts) to "required".
But, when I retrieve this layout from the API, the field in question's "nillable" attribute is TRUE when it should be FALSE.
Does salesforce expect data like this to be retrieved from somewhere else? Regardless it seems the API is lying.
The API is not lying - the field is only required by that particular layout, not by the underlying system.
If you want it to truly be required, you need to set this attribute on the field itself.
I'm building my first CodeIgniter app - and have a registration form. I'm using the built-in form validation class to validate the data, and am at the point of adding that data to the database.
Should I be taking that data from the form validation class or from the input class ($this->input->post('username'))?
I'm guessing the correct way is from the input class, but just wanted to be sure. If that's the case, if there any prepping of the data I need to do before it gets inserted into the database such as 'trim'?
Thanks
Yes you would get the data from the input class. Operations such as trim() can be done using the form validation library by adding the trim to the set of rules for validation. When the validation is done, your data is ready to be inserted to the database.
I've always used $this->input->post('lalal'); and found it to work since the validation is already done when i use the values. But you could also use the set_value('lalal'); helper function, this is particularly useful if you found an error but don't want the user to entery every form field again but just the one that was faulty.
Your prepping of the data should be in the validation rules, you can add any php-functions that take one argument, ie trim, also you can call on the helper functions CI offers if they are loaded when the validation happens. And you have the built-in's that CI has with the validation class.
For more info check out: http://codeigniter.com/user_guide/libraries/form_validation.html#thecontroller
I have a form where a user can enter a location address as well as the utility companies that provide service to that address. The Utility data is associated to the building:
Location hasMany Utility
Solely within the context of the utility, the name field is required so there's validation indicating as much. Within the context of a location, though, any utility information is optional. The user can choose not to enter that data when entering a location which would simply indicate that they don't want to associate the location with any or all of the utility companies we track.
Using the FormHelper, though, the validation is detected and the field gets marked as required. I want to retain that validation for the instances where utility data is being entered independently, but remove the required indicator on the location form.
I know I can hack this in any number of ways (e.g. removing the required class via javascript, etc.), but I'm wondering if there's a clean way to do this using the Cake API. I haven't seen anything obvious, so I'm hoping someone else has been here and found a clean, simple solution.
Thanks.
You can either ask the user how many utilities they want to add before creating the form, or you can add the Utility record inputs dynamically using js (the later is more work to do, and not as error-proof as the former).
An example of the view (if you want to do it in 1 view):
if (empty($this->data){
// a form to ask how many utility records the users want to create.
}else{
// generate the form based on user input.
}
I assume you know what to do in the controller.
I would add a class to the form element that are optionnal, and use that class to override the "required" indicator.
In fact there is a Cake solution, use the error param
$this->Form->input('Model.field', array('error' => false));
To disable error message output set the error key to false.