#1 2018-09-21 20:56:02

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Variable input parameters as array on MVCViewModel

On my application I have a HTML form with select2:

<select class="form-control select2" id="Contacts" name="Contacts" multiple="multiple" data-placeholder="" style="width: 100%;" value="{{Project.Contacts}}">
 {{#Contacts}}
 <option value="{{{ID}}}" {{{Status}}}>{{{Ident}}}</option>
 {{/Contacts}}
</select>

The user can select more option so when the user submit the form I have a URI like this:

...&Contacts=10&Contacts=11...

How can I handle this on MVCViewModel?
I should have an array on MVCViewModel so I have define a variant and try with:

with _Safe(Contacts)^ do
for j := 0 to Count-1 do
  begin
	if VariantToInt64(Values[j], ido) then
	  project.DynArray('Contacts').Add(ido);
  end;

but NOT work.

I have the feeling that the framework with considering this possibility.
In fact I think it use only last value of Contacts variable (11 on my example).

Am I wrong?

Note I have also try to use "name="Contacts[]" on form.

Offline

#2 2018-09-22 08:14:18

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,207
Website

Re: Variable input parameters as array on MVCViewModel

One variable name in URL = one variable value on server side...
This was as designed, and there is no such feature as "automatic array".

This "multiple" tag is indeed not handled yet.

Offline

#3 2018-09-22 22:04:35

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: Variable input parameters as array on MVCViewModel

ab wrote:

This "multiple" tag is indeed not handled yet.

Is there an alternative way to handle multiple selection input of html form?
On my application should have many multiselection input.

Offline

#4 2018-09-24 09:12:13

Chaa
Member
Registered: 2011-03-26
Posts: 244

Re: Variable input parameters as array on MVCViewModel

You can access raw input parameters:

var
  i: Integer;  
  LContacts: TRawUTF8List;
begin
  with CurrentServiceContext.Request do
  begin
    for i := 0 to (Length(InputPairs) shr 1) - 1 do
    begin
      if InputPairs[i * 2] = 'Contacts' then
      begin
        LContacts.Add(InputPairs[i * 2 + 1]);
      end;
    end;
  end;
end;

Offline

#5 2018-09-25 10:49:56

array81
Member
From: Italy
Registered: 2010-07-23
Posts: 411

Re: Variable input parameters as array on MVCViewModel

Chaa wrote:

You can access raw input parameters

Thanks for you suggestion.

Offline

Board footer

Powered by FluxBB