I just noticed that if the field is made required, then due to the way the module doesn't add a #title to the actual "number" component, you just get a nice red box with no message as to what was going on.

Comments

cdale’s picture

Here's a patch that corrects the issue, though, I'm not sure if we need to do more to support phone usage as a stand alone FAPI element. Thoughts? How would this normally be solved?

cdale’s picture

Above patch is broken. Working on a fix.

cdale’s picture

Status: Needs review » Needs work
cdale’s picture

Status: Needs work » Needs review
StatusFileSize
new2.26 KB

Updated patch. I think this is a better approach, and solves the issue.

cdale’s picture

StatusFileSize
new2.27 KB

One of those days. Couldn't sworn I added the !empty($error) check....

cdale’s picture

StatusFileSize
new2.3 KB

Definitely one of those days...

Nephele’s picture

Just to quickly chime in with a different option. It's possible to provide a '#title' to the original element, but then specify '#title_display' => 'invisible'. That makes the title not appear on the edit form, but yet be available for error messages. I'm not sure whether that ends up being a better alternative.

cdale’s picture

That would be ideal, except the $element['#title'] that gets provided to us in hook_widget_form(), is empty when it the cardinality is not 1. So what we get, is no #title, which, we can still output a message but I like the idea of making people aware which field is actually causing the issue, especially if they for some reason have many phone fields on the one form. I.m open to suggestions. I'm not 100% happy with the bubbles code either, but before that, I actually had an if(!empty($element['#title'])) display one message, or show something slightly different otherwise. The only difference, was that one included a name, and one did not.

This does seem somewhat related to a core issue I found, #980144: Issues with "required, multiple" fields in forms. Some of the first patches here make sense, but the final ones look to be rather broken for us, as for example, they remove the "ext" label. There has not been movement in that issue for sometime however.

I'm torn which way to go here, the code currently in place works for all use cases I tried, which I like. It's just a question of whether that is acceptable.

cdale’s picture

cweagans’s picture

Title: [7.x-2.x] Making a phone field required does not present error message » Making a phone field required does not present error message
cweagans’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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