Try ERPNext Buy Support Partners Foundation

How to filter link field in web form

how to filter link field in web form

frappe.web_form.on('area', (field, value) => {
filterCity(area);
}

function filterCity(area) {
  $.ajax({
    url: `api/resource/City?filters=[["City","area","=","${area}"]]`,
    success: function(result) {
      var options = []
      for (var i = 0; i < result.data.length; i++) {
        options.push({
          'label': result.data[i].name,
          'value': result.data[i].name
        })

      }
      var field = frappe.web_form.field_group.get_field('city');
      field._data = options;
      field.refresh();

    }
  });
};
2 Likes

It’s not working. Could you define the process.

Same here, couldn’t make it work.

Worked. Had to insert below into Custom Script

frappe.web_form.on('area', (field, value) => {
	filterCity(value);
});

function filterCity(area) {
    var myurl = 'api/resource/City%20Doctype?filters=[["City%20Doctype","area","=","' + area + '"]]';
	$.ajax({
		type: 'GET', 
		url: myurl,
		success: function(result) {
			var options = [];
			for (var i = 0; i < result.data.length; i++) {
				options.push({
					'label': result.data[i].name,
					'value': result.data[i].name
				});
			}
			var field = frappe.web_form.get_field("city");
			field._data = options;
			field.refresh();
		}
	});
};

edit: To make code more readable, replaced Blockquote markup with ```