Show percent symbol (%) in form

Hello I want to show percent symbol of field percent in form like shown in child table

in form view the percent symbol doesn’t appear

Capture d’écran du 2023-12-14 12-58-58

but in child table view the percent symbol appear
Capture d’écran du 2023-12-14 13-03-42

I want to show percent symbol in field percent in form

any help please

Hi @Hela_Guesmi:

I think there is not an easy and “clean” way, but … try this …
Create a client script, for your doctype, with this code.

frappe.ui.form.on('yourdoctype', {
	refresh(frm) {
		currentValue = frm.doc.your_percent_field
		$('[data-fieldname="your_percent_field"] input').val(currentValue + "%")
	},
	your_percent_field(frm) {
		currentValue = frm.doc.your_percent_field
		$('[data-fieldname="your_percent_field"] input').val(currentValue + "%")
	}
})

Hope this helps.

1 Like

thanks but do you know where can i modify code in standard code source frappe because i want it for all field percent

Hi @Hela_Guesmi:

Percent control “inherits” Float control behavior.

So it should works changing this function, this way:

format_for_input(value) {
		var number_format;
		if (this.df.fieldtype === "Float" && this.df.options && this.df.options.trim()) {
			number_format = this.get_number_format();
		}
		var formatted_value = format_number(value, number_format, this.get_precision());
		
		if (this.df.fieldtype === "Percent") {
			formatted_value += "%";
		}

		return isNaN(Number(value)) ? "" : formatted_value;
	}

I don’t know if it could break anything …

Anyway, altering base code is not the recommended method, because this changes will be gone with any further update.

Hope this helps.

3 Likes

thank very much @avc

how can i make work with both separator comma (,) and dot(.)
for exemple actually 10.05% work but 10,05% ignore and become 10.00%