Closed Bug 818270 Opened 12 years ago Closed 7 years ago

Changing maxlength on an input with display: none doesn't change the maxlength

Categories

(Core :: DOM: Editor, defect, P3)

16 Branch
x86
macOS
defect

Tracking

()

RESOLVED DUPLICATE of bug 1352799
blocking-b2g -

People

(Reporter: scott.gonzalez, Unassigned)

References

()

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1

Steps to reproduce:

Set maxlength on an input that is hidden with display: none


Actual results:

The maxlength did not change.


Expected results:

The maxlength should change to the specified value.
Originally reported against jQuery UI: http://bugs.jqueryui.com/ticket/8879

Our triage team says this was introduced in Firefox 4.
Yeah, unfortunately the maxlength enforcement is handled by the editor, which will not be around when the element doesn't have a frame attached to it...
Status: UNCONFIRMED → NEW
Ever confirmed: true
(In reply to Ehsan Akhgari [:ehsan] from comment #2)
> Yeah, unfortunately the maxlength enforcement is handled by the editor,
> which will not be around when the element doesn't have a frame attached to
> it...

Ehsan, shouldn't nsTextEditorState.cpp take care of that? I would think that nsTextEditorState::PrepareEditor should set the maxlength on the editor.
This looks like a bad reduction. Using elem.maxLength (capitalization) or elem.setAttribute( "maxlength", ... ) is working. I'll continue reducing the problem from the original jQuery UI report and figure out the actual case where this is failing.
I've updated the linked test case. In order for the bug to occur the original maxlength and style must be set via JavaScript. The original test case set them directly in the markup, and the bug did not occur, it just appeared broken because of the incorrect casing on the property name.
(In reply to Mounir Lamouri (:mounir) from comment #3)
> (In reply to Ehsan Akhgari [:ehsan] from comment #2)
> > Yeah, unfortunately the maxlength enforcement is handled by the editor,
> > which will not be around when the element doesn't have a frame attached to
> > it...
> 
> Ehsan, shouldn't nsTextEditorState.cpp take care of that? I would think that
> nsTextEditorState::PrepareEditor should set the maxlength on the editor.

Yes, I think that would be the right fix.
Hi,

In my experiments, first time (if no maxlength is assigned), it works correctly.

If you try to update it (with display: none) it didn't work.

Fails using .maxLength but Using setAttribute works correctly.
(In reply to Fernando R. Sela [:frsela] from comment #7)
> Hi,
> 
> In my experiments, first time (if no maxlength is assigned), it works
> correctly.
> 
> If you try to update it (with display: none) it didn't work.
> 
> Fails using .maxLength but Using setAttribute works correctly.

Finally worked in my box but not on B2G18 :(
the patch in 910151 is not ok;
set the input.maxlenth for the secend time, it' not ok;
blocking-b2g: --- → leo?
the pr 910151 is MNT pr;
(In reply to Fernando R. Sela (no CC, needinfo please) [:frsela] from comment #7)
> Hi,
> 
> In my experiments, first time (if no maxlength is assigned), it works
> correctly.
> 
> If you try to update it (with display: none) it didn't work.
> 
> Fails using .maxLength but Using setAttribute works correctly.

Dear frsela:
   Does setAttribute will work correctly??
(In reply to buri.blff from comment #11)
> (In reply to Fernando R. Sela (no CC, needinfo please) [:frsela] from
> comment #7)
> > Hi,
> > 
> > In my experiments, first time (if no maxlength is assigned), it works
> > correctly.
> > 
> > If you try to update it (with display: none) it didn't work.
> > 
> > Fails using .maxLength but Using setAttribute works correctly.
> 
> Dear frsela:
>    Does setAttribute will work correctly??

As I told in comment #8, it worked in my box with firefox nightly >22 but not in B2G18 build so finally I added a Timeout in order to change it after the box is displayed.
(In reply to Fernando R. Sela (no CC, needinfo please) [:frsela] from comment #12)
> (In reply to buri.blff from comment #11)
> > (In reply to Fernando R. Sela (no CC, needinfo please) [:frsela] from
> > comment #7)
> > > Hi,
> > > 
> > > In my experiments, first time (if no maxlength is assigned), it works
> > > correctly.
> > > 
> > > If you try to update it (with display: none) it didn't work.
> > > 
> > > Fails using .maxLength but Using setAttribute works correctly.
> > 
> > Dear frsela:
> >    Does setAttribute will work correctly??
> 
> As I told in comment #8, it worked in my box with firefox nightly >22 but
> not in B2G18 build so finally I added a Timeout in order to change it after
> the box is displayed.

we find the timeout patch is not ok for v1.1
Not blocking - we've shipped multiple platforms with this bug already and the blocking bug had a workaround implemented to get around this issue.
blocking-b2g: leo? → -
(In reply to Jason Smith [:jsmith] from comment #14)
> Not blocking - we've shipped multiple platforms with this bug already and
> the blocking bug had a workaround implemented to get around this issue.

Jason Smith:
   can you tell me how to workaround this pr?
Assignee: nobody → acperez
(In reply to Jason Smith [:jsmith] from comment #14)
> Not blocking - we've shipped multiple platforms with this bug already and
> the blocking bug had a workaround implemented to get around this issue.

we don't find this pr in v1.0.1
It appears this issue was first reported years ago here:

https://bugzilla.mozilla.org/show_bug.cgi?id=350786

I'm still experiencing this issue in Firefox 26.0 

Forgive my ignorance as this is the first issue I've been involved with with Firefox  - I see that is bug is set to NEW however there has been talk of a proposed workaround.

What is the state of this issue - is there a solution that has not yet been released or is there no known solution?
Flags: needinfo?
A potential solution is proposed in comment 6, but nobody has implemented it yet. If you or a friend have C++ experience, feel free to give it a try: https://developer.mozilla.org/en/Simple_Firefox_build
Flags: needinfo?
Component: Untriaged → Editor
Product: Firefox → Core
Assignee: acperez → nobody
The behavior is very strange.

If i try to set a value for maxlenght when display is "none", maxlenght doesn't change and I can't set the same value.

The code:  

    <input id="t1" type="text" display="inline-block"><p id="t2">max: 20</p>
    <input id="b1" type="button" name="b1" value="2" onclick="document.getElementById('t1').setAttribute('maxlength','2'); document.getElementById('t2').innerHTML='max: 2'">
    <input id="b2" type="button" name="b2" value="3" onclick="document.getElementById('t1').setAttribute('maxlength','3'); document.getElementById('t2').innerHTML='max: 3'">
    <input id="b3" type="button" name="b3" value="4" onclick="document.getElementById('t1').setAttribute('maxlength','4'); document.getElementById('t2').innerHTML='max: 4'">
    <input id="b4" type="button" name="b4" value="able" onclick="var el = document.getElementById('t1'); (el.style.display=='none')? el.style.display='inline-block' : el.style.display='none';">

The test:

a) press 2(p2), disable, p3, enable (maxlenght is 2 yet!), p3 (maxlenght is 2 yet!), p4 (maxlenght is 4 now)
b) press 2(p2), disable, p3, enable (maxlenght is 2 yet!), p4 (maxlenght is 4 now), p3 (maxlenght is 3 now)
> If i try to set a value for maxlenght when display is "none", maxlenght
> doesn't change and I can't set the same value.
When the textbox is get back visible, i can't set the same value i tried to set when display was none (test a).
In version 50.1.0, it's still broken. I can't use a newer version since it introduced two new bugs that I can't program with. :(

http://818270.foshin.com/ for another case. The display: none is set by CSS and JavaScript is used to set or remove an attribute that, in turn, triggers the display change. If the spans are clicked back and forth, they work since the editor is not hidden in-between. However, as soon as it is closed, either by cancelling or updating the value, it breaks.

Interestingly enough, if the broken element is inspected, it clearly shows the maxlength attribute with the correct value. Too bad it's ignored.
Priority: -- → P3
As long as I test, I have already fixed by bug 1352799.  If not fixed, please reopen this with test case.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.