Setting Default Language via Category with jQuery

3 years 4 months ago - 3 years 4 months ago #62756 by iamrobert
If you use 2 languages, my clients often forget to set the correct language for the item when creating a new item and they leave it at "ALL"..

So - if I add the following code to my admin template js - it will choose English by Default.

For instance my maincat with category id 10 is "clients" and is in English.
if (window.location.href.indexOf("&maincat=10") > -1) {
$(document).ready(function(){
$("select#jform_language").val("en-GB");
});
}

You can also do it via type.
if (window.location.href.indexOf("&typeid=23") > -1) {
$(document).ready(function(){
$("select#jform_language").val("en-GB");
});
}

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

3 years 4 months ago - 3 years 4 months ago #62758 by germany_bw
You can also set default language for new items in fc-global config in TAB "item form" or alternativ for each content type an other language as default in its config. (then in TAB "Item Form FE")

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

3 years 4 months ago - 3 years 4 months ago #62765 by iamrobert
Thanks - I was more meaning - you can set it for multiple languages - which means you don't need to worry about maintaining multiple content types based on languages. Also - you can add it in FLEXIContent type - Item Form BE tab under JS.

So - you can do this:



/* CHINESE */
if (window.location.href.indexOf("&typeid=23&maincat=61") > -1) {
 
$(document).ready(function(){
$("select#jform_language").val("zh-TW");
$("select#jform_catid.scat").val("61");
});
 
}
Attachments:

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

3 years 4 months ago - 3 years 4 months ago #62766 by micker
maybe i can add this in my admin module ?
set type cat language

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.

3 years 4 months ago #62842 by iamrobert
Hi MIcker,

It would be awesome.

However - I don't think there is a way to pass the language through the URL:
www.flexicontent.org/forum/20-general-su...tom-url-filters.html

Thanks,

Robert

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

3 years 4 months ago #62843 by micker
i will ask to georgios about model

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.

6 days 15 hours ago - 6 days 15 hours ago #77453 by iamrobert
Updated Code that works better with select2.js:

Via Category
(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:
(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);

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

6 days 11 hours 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.

6 days 1 hour 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.

5 days 22 hours 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.

Moderators: vistamediajoomlacornerggppdk
© 2018 Flexicontent. All Rights Reserved.