Try our conversational search powered by Generative AI!

Complex form element

A S
A S
Vote:
 

I want to build form, where will be two selection inputs. One of them gets data immediately from service and the other one gets data from service based on selected value in previous. So it's like "Pick country" -> "Pick city". Don't know which solution is the best, but I think that this should be one complex form input block with two blocks inside. But it seems that it's not possible because epiforms "understands" only children form inputs. Please, help.

#184967
Nov 07, 2017 14:43
Vote:
 

It is possible to create custom element with 2 blocks inside then do your business. Please see the Address and DateTime element in samples project here: https://github.com/episerver/EPiServer.Forms.Samples

Note that you might need to override the method getCustomElementValue to return data from your custom element in format you want.

Hope this help.

#184989
Edited, Nov 08, 2017 5:15
A S
Vote:
 

Thanks, that's a lot help, I dont know how I would come to this alone. However, getCustomElementValue doesn't do exactly what I want. I want that every field inside block sends separately. For example, it's working like this:

{Address:{Country: USA, City: NY}}. And I need this:

{Country: USA, City: NY}.

This is why I tried to put two form blocks inside another. Is there a workaround?

#185105
Nov 09, 2017 13:50
Vote:
 

I've got the same problem. I'm having to do my address as one field, but I'd really like to save each part of the address as a separate field when the form is sent.

#185107
Nov 09, 2017 13:55
Vote:
 

You can return your data in any format you want. You can override the method GetSubmittedValue() in your custom element to do that. Please see that method on the file AddressElementBlocks.cs.

#185119
Nov 10, 2017 3:30
A S
Vote:
 

Like I said, this method is responsible for "{Country: USA, City:NY}" but when form is submitted, the result is "{Address{Country:USA, City: NY}}.

#185159
Nov 10, 2017 6:45
Vote:
 

I mean, instead of using the sample serialize object, you can modify code to serialize the object yourself then you have full controlled how the returned object should look like...

#185167
Nov 10, 2017 7:36
A S
Vote:
 

Not the full controlled. I dont need "address" part in response

#185170
Nov 10, 2017 8:23
Vote:
 

The "Address" is your element's name and its value is a json object in the right part. Let say you have 2 elements: Address and Email, you need something to know which data belong to the Address and which belong to the Email. Right? If you only need to send the value WITHOUT element name, you can create your custom actor then do yourself. The default CallWebhookAfterSubmissionActor can sent in JSON format or "name=value" format.

#185172
Nov 10, 2017 8:43
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.