Creating our own custom Options to be used in fields

Hi, I would love to know if there is any way to create our own custom options to be used in fields

an example if we are going to make an email field we would add Email to the options Textarea for that respective field so it will validate the field same goes for Phone.

My question is can I for example create my own option let’s say English or Arabic so if I added it to the options Textarea it will validate my field

Thank you

Cannot be done out-of-the-box, needs customization

Can you please redirect me? if there are any documents of source that I can follow to do so. coding is not an issue for me, I am just new to ERPNext. Thank you

You need to get a developer to do it. I can assist you with it

I am a developer myself, your help is much appreciated but I would love it if you can redirect me to the correct class and methods that enable me to do so.

Thank you

@mohammed_fowzi are talking about changing the select options according the other dependency ?

Hi @bahaou I mean that if there is a way to create pre-defined global options via server script for any field type as the example about ( Email, Phone, DocType name in case of Link field)?

Thank you

@mohammed_fowzi sorry , I still can’t understand you

@bahaou,
I want to change the behavior or the validation of a field based on options. for example, for a data field, if I typed “Arabic” in the options, this field will only accept Arabic characters. I know I can achieve this using custom client validation, but I just wanted to know if it is possible to extend fields with additional options.

Never Mind I found what I was looking for under

frappe/frappe/public/js/frappe/form/controls/data.js

if(this.df.options == 'Phone') {
		this.df.invalid = !validate_phone(v);
		return v;
	} else if (this.df.options == 'Name') {
		this.df.invalid = !validate_name(v);
		return v;
	} else if(this.df.options == 'Email') {
		var email_list = frappe.utils.split_emails(v);
		if (!email_list) {
			return '';
		} else {
			let email_invalid = false;
			email_list.forEach(function(email) {
				if (!validate_email(email)) {
					email_invalid = true;
				}
			});
			this.df.invalid = email_invalid;
			return v;
		}
	} else {
		return v;
	}
},

Thanks for everyone

1 Like