⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Multiselect Field Type



j-gun
  • profile picture
  • Member

Posted 04 February 2013 - 06:15 AM

Dear all,

 

I use multiselect field type in grocery CRUD for my percentage number (0%, 10%, 20% .... 100%). The problem occurs when i try to select > 1 option for example 20% 50% 30%.

 

Every the data form saved, the multiselect will automatically sort it Descending. So in my database the order of percentage change to 50% 30% 20%. Why it happens and how to turn off the auto sort from multiselect field type?

 

Thanks


jeanjunker
  • profile picture
  • Member

Posted 04 September 2017 - 23:56 PM

J-gun,

Did you ever get a solution to this?

 

I too am having issues with the MulitSelect.

 

The values (indexes) seem to be saved in low-to-high order regardless of the order I chose them in.

I need them to stay in the order that I selected the items...

 

Jean.


Amit Shah
  • profile picture
  • Member

Posted 05 September 2017 - 04:36 AM

Hi Jean,

 

Can you share the structure and the code.. i might be able to help you out on the same. I have used multi-select and am able to sort it out correctly on the order set ..

Do share the code & Structure .. and may be we could come 2 a solution


jeanjunker
  • profile picture
  • Member

Posted 06 September 2017 - 07:13 AM

Amit Shah,

Yes, See below where I show BOTH field_type settings that I have tried.

The "first try" example with the NUMERIC indexes is more like the GC example so I did that first, but the "second try" example is what I actually want so that the ALPHABETIC indexes get stored into my PurCheckFmt Field.

BOTH ways work fine as to allowing users to choose the values into a 'text' field type.

 

BUT THE PROBLEM IS that no matter what ORDER one chooses the multi-select values into the PurCheckFmt Field, they don't get saved into the DB Record in the order that I choose them. They visually appear in the correct order (the chosen order) at Form Edit but once I Save the Records, they are re-orderd into Low-High order into the Record.

 

I NEED them to stay in the order that I select them, that is the whole idea of letting the user choose the fields, to indicate to me the Order of things on the "Check", I use this information ("8/8Volume, NetValue, etc.) later in another Controller to Layout my GC Edit Form for another Table.

 

So, The ISSUE is only with the ORDER of how items are saved: how do I stop them from being re-ordered when saved into my table field?

 

I had a fieldCallback on another field on this form and did a quick Dump/Error_Log from the $post_array("PurCheckFmt") field but the choices had already been re-sorted by then, I guess its being done in the GC JavaScript somewhere?

 

I also tried the "set" Field_Type but it doesn't work either...

 

Any ideas appreciated:

 

$crud->change_field_type('PurCheckFmt', 'text'); #Text Field

 

SECOND Try:

$crud->field_type('PurCheckFmt','multiselect', array(

"8/8Volume" => "8/8Volume", "NetVolume" => "NetVolume",
"8/8Value" => "8/8Value", "NetValue" => "NetValue",
"8/8Marketing" => "8/8Marketing", "NetMarketing" => "NetMarketing",
"8/8Gathering" => "8/8Gathering", "NetGathering" => "NetGathering",
"8/8Transport" => "8/8Transport", "NetTransport" => "NetTransport",
"8/8SeverTax" => "8/8SeverTax", "NetSeverTax" => "NetSeverTax",
"8/8Amount" => "8/8Amount", "NetAmount" => "NetAmount",
"JIBNetted" => "JIBNetted",
"Legal" => "Legal",
"Interest" => "Interest",
"StateWH" => "StateWH",
"FedWH" => "FedWH",
"AlienWH" => "AlienWH"
));

 

FIRST Try:
$crud->field_type('PurCheckFmt','multiselect', array(
"1" => "8/8Volume", "2" => "NetVolume",
"3" => "8/8Value", "4" => "NetValue",
"5" => "8/8Marketing", "6" => "NetMarketing",
"7" => "8/8Gathering", "8" => "NetGathering",
"9" => "8/8Transport", "10" => "NetTransport",
"11" => "8/8SeverTax", "12" => "NetSeverTax",
"13" => "8/8Amount", "14" => "NetAmount",
"15" => "JIBNetted",
"16" => "Legal",
"17" => "Interest",
"18" => "StateWH",
"19" => "FedWH",
"20" => "AlienWH"
));


Amit Shah
  • profile picture
  • Member

Posted 06 September 2017 - 12:32 PM

well, usually a multiselect  (set_relation_n_n) will have a parameter - priority_field_relation_table ..

1st thing, if there is a possibility for you to maintain a table and do a set relation_n_n ... this problem will be resolved..

Not happening .. then there is another way to work around on the same

 

callback_insert ...

save the normal record..

now when u going to save this multiple entries of selection in seperate table, there - will recommend have a extra field (priority) ... and set the values in incremental order as per single entries goes in.

 

When displaying - u will require to retrieve the data basis of order for the priority field.

 

This should help you resolve the issue

 

Happy GCing :)


jeanjunker
  • profile picture
  • Member

Posted 06 September 2017 - 12:44 PM

Amit,

Thanks for your feedback, I will ponder and investigate the relation_n_n idea and maybe callback_insert.

 

But, I am not Inserting a record, I am just updating a text field in a record but I will try some callbacks and examine the $POST Array and see how it looks..

 

I am sure that I will have other development issues with my project, can I contact you via email about some of them?

 

Noodling on it...Jean.

 

jeanjunker {at} gmail {.} com


jeanjunker
  • profile picture
  • Member

Posted 18 September 2017 - 14:41 PM

Amit,

Or anyone who knows how to do this:

 

Is there a way in GC to specify a "Lookup" Field with a Table Relation BUT allow BOTH Looking-up a value from the Related Table AND/OR Typing in a New Value that does not exist in the table.

 

It seems like GC only lets you lookup a value.

I need to do both or either one with a single field on the same form depending on weather the user wants to lookup a value or type in a new one.

Is this possible?

 

Jean.