I created a custom link field. The field fetches from the Batch doctype. But when I enter a batch not in the list it clears the value. How do I stop this from happening? I want to use the value to create a new batch
Hi @zeeeeeeeero:
When you type a value that is not on the link field data origin (in this case no existing batch), just pressing Enter or choosing “Create a new batch” should shows a form for creating new one with batch number provided. This is the standard behavior …
Is this not working this way for you?
Oh yes it works like that. But my employers are demanding that instead of using the quick entry menu to add new batches they want to do it from the form directly. And I have a custom script for that. But it doesn’t work because the JS for the link field clears non-existing values
Hi @zeeeeeeeero:
Ok, I understand now… I see 2 possible ways
-
Override
frappe.client.validate_link
. This method check if data provided exists on the linked doctype. If doesn’t then data is cleared. -
Change your field type to autocomplete, and manually manage linking data. Basically, autocomplete is like a link field without standard link field behavior With client script, you can dynamically set data to the field and, in case of new batch, create new one.
Check this:
Maybe there is an easier way to achieve this … but … it’s still monday morning
Hope this helps.
Thankyou I’ll try this later and update here!