Setting Default Language via Category with jQuery

More
5 years 2 weeks ago - 5 years 2 weeks ago #77453 by iamrobert
Updated Code that works better with select2.js:

Via Category
Code:
(function($) { //VIA URL $(document).ready(function() { if (window.location.href.indexOf("&maincat=114") > -1) { $('#jform_language').val('en-GB'); // Select the option with a value of 'en-GB' $('#jform_language').trigger('change'); } }); }); })(jQuery);


Data Title:
In multi-lingual sites the the top level categories of the site are usually the languages (English & Chinese (中文)):







The top category uses data-title English or Chinese (中文):




So we can set this way:
Code:
(function($) { //VIA DATA TITLE $(document).ready(function() { var data = $("#jform_catid option:selected").attr('data-title'); if (data == 'English') { $('#jform_language').val('en-GB'); $('#jform_language').trigger('change'); } if (data == '中文') { $('#jform_language').val('zh-TW'); $('#jform_language').trigger('change'); } $('select#jform_catid').on('change', function() { var data = $("#jform_catid option:selected").attr('data-title'); if (data == 'English') { $('#jform_language').val('en-GB'); // Select the option with a value of 'en-GB' $('#jform_language').trigger('change'); } if (data == '中文') { $('#jform_language').val('zh-TW'); // Select the option with a value of 'zh-TW' $('#jform_language').trigger('change'); } }); }); })(jQuery);
Last edit: 5 years 2 weeks ago by iamrobert.

Please Log in or Create an account to join the conversation.

More
5 years 2 weeks ago #77454 by micker
cool you can do it with dashboard module V2 module too without js

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
5 years 2 weeks ago #77455 by iamrobert
Thanks - I was sharing as option 2 allows the user to swap languages automatically in new items based on category:



which has been one feature that has been bugging me forever.

Please Log in or Create an account to join the conversation.

More
5 years 1 week ago #77456 by micker
oh cool can it be more generic ?

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
10 months 2 weeks ago - 10 months 2 weeks ago #84812 by iamrobert
Updated Code for Joomla 4 and FLEXIContent:



Code:
//JS LANGUAGE (function($) { // Function to check and update the language function updateLanguage() { var selectedOption = $("#jform_catid option:selected"); var data = selectedOption.attr('data-title'); var text = selectedOption.text(); // Check if data-title attribute exists or use the option text var language = data || text; if (language) { if (language.includes('English')) { // console.log('English'); $('#jform_language').val('en-GB'); $('#jform_language').trigger('change'); } else if (language.includes('中文')) { // console.log('中文'); $('#jform_language').val('zh-TW'); $('#jform_language').trigger('change'); } } } $(document).ready(function() { // Initial check on document ready updateLanguage(); // Check on category change $('select#jform_catid').on('change', function() { updateLanguage(); }); }); })(jQuery);


Category Structure:

- English
- 中文 (Chinese)

Last edit: 10 months 2 weeks ago by iamrobert.

Please Log in or Create an account to join the conversation.

More
10 months 2 weeks ago #84814 by micker
thanks

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.840 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline