When creating a form element, if you give it a custom #name that doesn't match the source yml key value then form validation fails. I can edit the key value in the source yml file after creating elements to match the desired #name (supporting uppercase values) but this feels like a bug. Since you don't specify the key (it's auto-generated based on the field title), it seems like it should work regardless of the set #name attribute. I also tried setting it as a subitem of #attributes: name: TestInput and it's the same result, the markup is good but validation fails.

Fails:

test:
  '#type': textfield
  '#title': Test
  '#required': true
  '#name': TestInput

Works:

TestInput:
  '#type': textfield
  '#title': Test
  '#required': true
  '#name': TestInput
CommentFileSizeAuthor
#4 3009015-4.patch4.81 KBjrockowitz

Comments

nsciacca created an issue. See original summary.

jrockowitz’s picture

The #name attribute is not recommended and not available via the UI.

I think the source mode should enforce all element key's to be lower-cased with underscores.

nsciacca’s picture

I see... I agree that if uppercase is not supported then it should be validated and not allowed in the Source mode. As it is now, if you edit the Source and introduce uppercase, it appears to save and work, but using the UI for that element it throws an error saying the key needs to be lowercase.

As for the #name attribute - although it doesn't have a specific field for a "name" in the UI, you can set it either in the custom properties or on the element attributes. Again, if it's not supported, it shouldn't save/render in the markup the way it is - just leads it to be broken and confusing to the end user.

My specific project requirements is to post my form to a third-party that is expecting specific "name" values. So I'm going to attempt to do all my validation on the client side since posting to Webform's submission table is not required. Still, it would be nice if it custom name values were supported and didn't break the validation.

jrockowitz’s picture

Status: Active » Needs review
StatusFileSize
new4.81 KB

The attached patch validates element key entered via 'Edit Source'.

@nsciacca The #name attribute is "kind of supported" but breaks webform integration and validation.

To integrate with a third party, I recommend using the Remote Post handler

  • jrockowitz committed 8f2d39b on 8.x-5.x
    Issue #3009015 by jrockowitz: Can't submit required field with custom #...
jrockowitz’s picture

Status: Needs review » Fixed

I committed the patch. Please download the latest dev release to review.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.