How to set filter for the link field in web form?

Hi guys,
Can any one suggest me to set filter query for the link field which is in web form.

Regards,
Nivedha

Any idea to set filter in web form?

Hi @Nivedha. Did you manage to filter your link field? I am trying to do the same and would appreciate your insight.

My request also… but no solution until now.
The filter that works on desk form is not working on web form.

My way around is to duplicate the doctype but only filled with filtered data I want to be displayed in the webform.

Ah, I see. In my case, I am trying to create a type of warranty registration form for devices that a customer has bought from one of our resellers. I had been hoping to give the customer a link field for applicable Serial Nos to choose from, but for now I’ve just put in another field for them to type in the number as plain text to be reviewed by a staff member.

I see you need a dynamic filtered link field. Mine is static.

May be this is even better for proof of ownership (user can’t type in the serial number if he doesn’t have the device) :slight_smile:

You’re right. :thinking:

Hi @archais, @rahy, i have tried but filter is not set in web form.

Which one have you tried?
Because as I and @archais said we have not found any solution yet. So yes the filter is not working in webform…

I looked at the field df in the form object through the console and I found that it lists every possible record for the link field under options, so it is essentially working as a select field rather than a link field.

I tried the snippet below but didn’t work either:

frappe.web_form.after_load = () {
		frappe.web_form.set_query("account", function() {
			return {
				filters: [
					["Account","is_group", "=", 0]
				]
			};
		});
};

@archais seems to have hit the nail on the head. This means there’s no facility for regular link filtering built into Web Forms yet!

The only way I can think of to create a filtered link list is to write a python method which is called on refresh (and whenever fields that affect the filter are modified). The python method would have to run a query and return the list of available options. You would then load the list into the df property.

Wow! That’s a lot …I think this needs to be built into the core really

For now, my simple workaround is to set the field type as ‘Select’ (in the Web Form only). After that, export a manually filtered list of the link field doctype and paste that in the Options. It still shows up as a link field in the backend

Cheers

2 Likes

Nice. That sounds similar to the method I suggested. Do you use a whitelisted python method to do it, or are you doing it in the JS with frappe.get_list()?

No script… options are static. Thankfully, I only need the Web Form for a short duration and the options are unlikely to change within that time

If you do however achieve this by script, pls remember to post it here for future reference…

Cheers

Ah, I see. I might take a look at it later on, and will definitely post here if I do come up with a working solution. Currently, I’m working on my own SLA doctype.

BTW the redirect is also failing in V13… just in case you are able to find a work around while looking at the Web Form, kindly post here as well. I have another thread going for that though

Are you talking about the redirect on submission?

Yes, that is correct