SebastianP Posted May 6, 2019 Share Posted May 6, 2019 Hi, I have an autocomplete page reference field in my template. On typing I want to get only results in a certain language. So I tried something and found the solution in this selector: parent=/the_parent_page/,lang_id=18712,title!="" (lang_id is the id of the required language). So far, so good - BUT: when I select one ore more items by this field and then save the page, an error occurs "Field does not exist: lang_id" and the field is not saved. Can you help me? Thank you, regards Sebastian Link to comment Share on other sites More sharing options...
SebastianP Posted May 7, 2019 Author Share Posted May 7, 2019 I try to explain the situation better: my website has two languages, "default" and "english". In my template "article" are two page reference fields: "related articles" and "related articles english". Not all pages are translated to english, so the field "related articles english" holds sometimes a different selection of pages then the field "related articles". The backend user language is "default". On typing an english word in the field "related articles english", the selector should search in the english fields (title, body...) of the pages and return the results. This behaviour can I force with adding "lang_id=my_english_language_id" to the selector string. So I get the correct results with the english titles. But when I select/add a returned page to the field "related articles english" and try to save the page, an error occurs, because the field "lang_id" on the selected page dont exists. I'm wondering if there is a selecor string, who searchs in the english fields of a page, like "title_EN%=searchword" or something like that... Thank you for any suggestion or hint! Regards Sebastian Link to comment Share on other sites More sharing options...
Robin S Posted May 9, 2019 Share Posted May 9, 2019 @SebastianP, give this a try... 1. Remove the "lang_id=18712" portion of the selector string for the autocomplete field. 2. Add the following to the selector string for the autocomplete field: name!=12345 This part of the selector string is deliberately set to something that should always be true - in this case that the page name should not be "12345". The purpose of this is to let us identify the selector when it is sent in the AJAX request. 3. Add the following hook to /site/ready.php: $wire->addHookBefore('ProcessPageSearch::executeFor', function(HookEvent $event) { $input = $event->wire('input'); /// If this request is coming from the autocomplete field... if($input->get('name!') === '12345') { // ...then set the lang_id GET variable $input->get->lang_id = 18712; } }); 1 1 Link to comment Share on other sites More sharing options...
SebastianP Posted May 9, 2019 Author Share Posted May 9, 2019 Oh man - you are my hero! That works like a charms! Thank you, best regards! Sebastian 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now