Hybrid View

  1. #1
    Ext User
    Join Date
    Jun 2007
    Posts
    37
    Vote Rating
    0
    quilleashm is on a distinguished road

      0  

    Default emptyText is submitted with the form

    emptyText is submitted with the form


    Hi all,

    If I set emptyText on a text field, then if the form is submitted with the field 'empty' (but showing the emptyText) then the value of emptyText is submitted. I think this value should be display only and never submitted. Typically the value is some sort of prompt which isn't usually sensible to submit.

    Cheers.

    Mike.

  2. #2
    Ext User violinista's Avatar
    Join Date
    Apr 2007
    Location
    Serbia
    Posts
    293
    Vote Rating
    0
    violinista is on a distinguished road

      0  

    Default


    I noticed the same issue today. Is it bug or feature?

    Regards,
    Violinista
    "It is better to be young, pretty and rich instead old, ugly and poor."
    (c) Alan Ford.

  3. #3
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    NL
    Posts
    607
    Vote Rating
    1
    mdissel is on a distinguished road

      0  

    Default


    This is fixed in the SVN release

    Field.js
    Code:
        /**
         * Returns the raw data value which may or may not be a valid, defined value.  To return a normalized value see {@link #getValue}.
         * @return {Mixed} value The field value
         */
        getRawValue : function(){
            var v = this.el.getValue();
            if(v === this.emptyText){
                v = '';
            }
            return v;
        },
    
        /**
         * Returns the normalized data value (undefined or emptyText will be returned as '').  To return the raw value see {@link #getRawValue}.
         * @return {Mixed} value The field value
         */
        getValue : function(){
            var v = this.el.getValue();
            if(v == this.emptyText || v === undefined){
                v = '';
            }
            return v;
        },
    Thanks

    Marco

  4. #4
    Ext JS Premium Member prophet's Avatar
    Join Date
    Mar 2007
    Location
    Greenwich, CT
    Posts
    187
    Vote Rating
    0
    prophet is on a distinguished road

      0  

    Default


    It looks like this problem still exists in Ext 1.1 Beta 2 (as of today, 7/2/2007).
    Any hot fix suggestions?
    Brad Baumann

  5. #5
    Sencha User trbs's Avatar
    Join Date
    Mar 2007
    Posts
    310
    Vote Rating
    0
    trbs is on a distinguished road

      0  

    Default


    okey i wrote a small workaround for this.
    i'll have to say that i think this patch is less then ideal and i do not recommend patching ext in this way... but if you really want this problem solved try this:

    add the following lines of code to Action.js line 108:
    PHP Code:
      if (o.clientValidation === false || this.form.isValid()){
        
    this.form.items.each(function(f) {
            if (
    f.el.getValue() == f.emptyText) {
                
    f.el.dom.value '';
            }
        });
        
    Ext.lib.Ajax.formRequest
    The first and last line of the code block are the existing lines. You'll need to add the this.form.items.each block between them.

    Explanation
    The form.submit() action uses a form serializer instead of the getValue() field functions the raw dom value is send to the server. (this is the value including emptyText if the field is empty)

    So the fix posted above does work, only not for a form.submit() action. Since i do not want to start editing in files other then those of ext themselfs. I build the above work around.

    Just before the XHR submit-request to the server, this deletes the emptyText value from the dom. Then when the Ext.lib.Ajax.formRequest serializes the form there is no emptyText in there anymore.

    The next time the form validates itself, the emptyText will reappear.

    Related problems
    You will also hit this problem if you use: form.getValues() as that method also uses the serializer.
    This patch will not work for that, but i could use a similar workaround. (again remember, this is not very good
    way to work around this... hopefully the ext team will come up with something better, like using getValue() methods or serializers that check for emptyText)

    Attachment
    The patched file attached here is based on the Ext 1.0.1 release.
    Please apply the workaround yourself or do a diff; if you want to apply it on any other version.

    Post Scriptum
    If your client types the same value as emptyText in your Field the workaround will not do the desired thing. It will consider the typed value the same as emptyText, which it is clearly not. For 9 out of 10 people this will not be a problem, but if it is you should also check the css (aka the light grey text, instead of black typed text)
    Attached Files

  6. #6
    Ext JS Premium Member prophet's Avatar
    Join Date
    Mar 2007
    Location
    Greenwich, CT
    Posts
    187
    Vote Rating
    0
    prophet is on a distinguished road

      0  

    Default


    trbs, you're a pro! thanks a lot!
    Brad Baumann

  7. #7
    Sencha User
    Join Date
    Dec 2008
    Posts
    27
    Vote Rating
    0
    hitekshu is on a distinguished road

      0  

    Default f.el is undefined

    f.el is undefined


    I am using Extjs 3.4 and there is an error "f.el is undefined" which is thrown if the element is a radio button. Any fix for this one?


    Quote Originally Posted by trbs View Post
    okey i wrote a small workaround for this.
    i'll have to say that i think this patch is less then ideal and i do not recommend patching ext in this way... but if you really want this problem solved try this:

    add the following lines of code to Action.js line 108:
    PHP Code:
      if (o.clientValidation === false || this.form.isValid()){
        
    this.form.items.each(function(f) {
            if (
    f.el.getValue() == f.emptyText) {
                
    f.el.dom.value '';
            }
        });
        
    Ext.lib.Ajax.formRequest
    The first and last line of the code block are the existing lines. You'll need to add the this.form.items.each block between them.

    Explanation
    The form.submit() action uses a form serializer instead of the getValue() field functions the raw dom value is send to the server. (this is the value including emptyText if the field is empty)

    So the fix posted above does work, only not for a form.submit() action. Since i do not want to start editing in files other then those of ext themselfs. I build the above work around.

    Just before the XHR submit-request to the server, this deletes the emptyText value from the dom. Then when the Ext.lib.Ajax.formRequest serializes the form there is no emptyText in there anymore.

    The next time the form validates itself, the emptyText will reappear.

    Related problems
    You will also hit this problem if you use: form.getValues() as that method also uses the serializer.
    This patch will not work for that, but i could use a similar workaround. (again remember, this is not very good
    way to work around this... hopefully the ext team will come up with something better, like using getValue() methods or serializers that check for emptyText)

    Attachment
    The patched file attached here is based on the Ext 1.0.1 release.
    Please apply the workaround yourself or do a diff; if you want to apply it on any other version.

    Post Scriptum
    If your client types the same value as emptyText in your Field the workaround will not do the desired thing. It will consider the typed value the same as emptyText, which it is clearly not. For 9 out of 10 people this will not be a problem, but if it is you should also check the css (aka the light grey text, instead of black typed text)