Hello everybody,
How to set a field number phone that dose not register if it doesn't contain at least 14 characters ?
I appreciate any help
Hello everybody,
How to set a field number phone that dose not register if it doesn't contain at least 14 characters ?
I appreciate any help
Hello Phuong Trinh,
You can do it through code.
First, locate the record.js
file for your specific module. You’ll typically find it at the following path:
custom/modules/yourModule/clients/base/views/record/record.js
({ extendsFrom: 'RecordView', initialize: function (options) { this._super('initialize', [options]); this.context.on('button:save_button:click', this._save_desc, this); }, _save_desc: function (model) { let phone = this.model.get('phone_mobile'); // Convert the number to a string let phoneString = phone.toString(); // Get the length of the string let length = phoneString.length; if (length < 14) { app.alert.show('error', { level: 'error', messages: 'The length was less than 14 digits', autoClose: false }); } else { // do something } }, })
From this you can acheive what you want.
Thank you...
Is this field a varchar (number + formating) or a integer (number only)?
If it is an integer field then you can specify the minimum and maximum value via Studio.
hello André, how can i specify the minimum value via Studio in my case ?
You can find it here. You need to make sure that the target field is an integer one, then both attributes Max Value and Min Value will be available.
Hi Phuong Trinh ,
I believe you are seeking custom field validation. If so, you will likely want to review this article to add logic that prevents the record view save in the event of errors:
https://support.sugarcrm.com/documentation/sugar_developer/sugar_developer_guide_13.3/cookbook/adding_field_validation_to_the_record_view/
Heres a quick example I put together for a create view controller that checks for the name fields length. FYI, this hasn't been tested:
({ extendsFrom: 'CreateView', initialize: function (options) { this._super('initialize', [options]); //add validation tasks this.model.addValidationTask('check_length', _.bind(this._doValidateLength, this)); }, _doValidateLength: function(fields, errors, callback) { //validate length if (this.model.get('name').length < 5) { errors['name'] = errors['name'] || {}; errors['name'].required = true; } callback(null, fields, errors); } })