Open Bug 805049 Opened 12 years ago Updated 3 hours ago

Allow input elements (or text fields in general) to show text that isn't the current element's value

Categories

(Core :: DOM: Forms, defect)

defect

Tracking

()

People

(Reporter: mounir, Unassigned)

References

(Blocks 2 open bugs)

Details

Attachments

(1 file, 1 obsolete file)

I don't think working on that would be trivial but that would help us implementing a better user experience with forms and validation: we could easily validate forms that doesn't "look" valid but are actually valid. There are few examples, bug 802860 is one of them.
I'm not really sure what the summary means here.  Can you please clarify?
For example, if a user types in an <input type=url>:
"www.foo.com"
the underlying value should be:
"http://www.foo.com"

Same if a user types in an <input type='number'> with a french local:
"42,3"
the underlying value should be:
"42.3"
(In reply to comment #2)
> For example, if a user types in an <input type=url>:
> "www.foo.com"
> the underlying value should be:
> "http://www.foo.com"
> 
> Same if a user types in an <input type='number'> with a french local:
> "42,3"
> the underlying value should be:
> "42.3"

I see.  How do you suggest we go about doing that?  The obvious way would be a third anonymous div, but that could be sort of crossing a line in terms of code complexity, etc.
I don't think we need that. We should not have the real .value in the layout, only the one being shown. Ideally nsTextControlState should be able to return the value. The shown if it's the same as the real one. The other one otherwise.
Alternatively, we could have this involving the editor.
(In reply to comment #4)
> I don't think we need that. We should not have the real .value in the layout,
> only the one being shown. Ideally nsTextControlState should be able to return
> the value. The shown if it's the same as the real one. The other one otherwise.
> Alternatively, we could have this involving the editor.

OK, that makes more sense.
Blocks: 849611
Attached patch Example patch. (obsolete) — Splinter Review
What about having a GetValue() method returning a sanitized version of @value (e.g. when requested by javascript or when sending to server), and GetRawValue for internal purposes? I'm attaching a quick patch to explain what I mean, let me know what you think. Thank you.
I apologise for the nonsense in the previous patch. 

I have been thinking about this in the background, and maybe now I've come up with something that makes sense. 

What I'm doing here is similar to what Mounir suggested in comment #4. Since nsTextEditorState is agnostic of the actual Type of the input element, it cannot be in charge of the actual validation. To solve this I added a new member in nsITextControlElement, 

nsITextControlElement::SanitizeValue(nsAString& aValue) const

this new member would sanitize the value accordingly. 

This member is then used in nsTextEditorState::GetValue to sanitize the value before returning it.

This way, e.g. 

<input type="email" value="  agi.novanta@gmail.com" />

would have a @value="agi.novanta@gmail.com". 

Thank you!
Attachment #8391984 - Attachment is obsolete: true
Attachment #8420550 - Flags: feedback?(jst)
Blocks: datetime
No longer blocks: datetime
Comment on attachment 8420550 [details] [diff] [review]
Allow Input to display text which is different from their @value

clearing old request.
Attachment #8420550 - Flags: feedback?(jstenback+bmo)
Severity: normal → S3
Component: DOM: Core & HTML → DOM: Forms

There has been this fix in comment 8 for five years now, which seems to get no attention any more. I would appreciate it if we could fix this issue now. What is missing? How can I help to get it done?

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: