Link Filed filters

Hello!

In Frappe, we can use the frm.set_query method to apply filters on link fields. However, even after applying filters, if a user copies the ID of a record that does not match the filter criteria and pastes it into the link field, Frappe still accepts it.

Example:
I have a Contact link field. In the Contact master, there are both Indian and foreign numbers.
I want the link field to show only Indian numbers. Using frm.set_query, this can be achieved.

But if someone copies the ID of a foreign contact and pastes it into the Contact link field, it gets accepted—even though it’s not in the filtered list.
I want to restrict this behavior so that only records matching the filter can be selected.

Can anyone help me with this?

You can add validation on server side, it would be more better way to do it.

@Abdeali Yeah, i did like that only.
But i need it in a global level.

How can we override the core method?

Log in as the original Administrator and keep deveop_mode as true … be very careful when messing with the core

By the way have you tried client script rather than server script?