11 years ago
Topic

Hello,


In drop-down list (Select - Simple), is there a way to limit the number of selected subjects/options to only 2 ? 

If there is a way, than how ?

Thank you all,

Ofer.

http://www.profilu.co.il

Get a VIP membership
46 Posts
Castor
11 years ago
2
Level 1

Hi Ofer1984,

This works only with drop-down lists from type multiselect. With Seblod and a little jQuery-snippet in your creation form - click on the orange button, at the end of this form, in section Script (JS) you have to put this code (first line and last line not necessary):

$(document).ready(function() {
  var maxselected = 2;
  var selection = null;
  $('#your_select_multiple').change(function(event) {
   if ($(this).val().length > maxselected) {
    $(this).val(selection);
   } else {
    selection = $(this).val();
   }
  });
});

Best regards

Castor

Remark: your_select_multiple is the Name * from your multiple-select field

11 years ago
1
Level 2

Hi Castor,


Thank you so much. I wouldn't have done it without your help :)

Regarding the last question, since I have  info in my database, will something get lost if I apply these changes ?

For example, if the drop-down list that I have contain 3 values: A, B, C. and I chose the value A > then I converted the list into a multiselect >  Will it still remember the value A that I chose before the conversion (or will it delete/reset the drop-down list's info) ?


Thank you again,

Ofer

http://www.profilu.co.il

46 Posts
Castor
11 years ago
0
Level 3
Hi Ofer1984,
generally there is no risk if the field is not a joomla core field. Never change the core fields! In your case it makes no difference multiselect or not.
In case of multiselect a single-value is stored in the same way as a single-value from a simple-select in this form: A. From two values all values are stored with the separator (standard: comma) in this form: A,B,C - after the change of type avoid to change the separator.

In order to find your entries in your searchform you have to use button 3 (Match + Stage) under Words | Any Words for OR or Words | Each Words for AND in your query. For multiple never use ... Exact

When changing type from multiple to simple you will have problems with matching your entries. For this reason, you should not use more  ... Exact also

Best regards
Castor


11 years ago
1
Level 1

Hi Ofer1984,

To respond to your last question: 

For example, if the drop-down list that I have contain 3 values: A, B, C. and I chose the value A > then I converted the list into a multiselect >  Will it still remember the value A that I chose before the conversion (or will it delete/reset the drop-down list's info) ?




When you change the simple to multiple dropdown field, you will find the value stored with the simple drop-down field.

Regards,
Mehdi.

11 years ago
0
Level 2

Thank you very much ! :)

These explanations helped me a lot !

Get a Book for SEBLOD