Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to make an TextItem as readonly

    Can anyone tell me, how to set the readonly property to a TextItem in SmartGwt??

    Thanks & Regards,
    Kothandaraman N.

    #2
    TextItem.setDisabled(true);

    Comment


      #3
      There is the better way

      Code:
       ...
       readOnly(textItem.getName());
       ...
      
      
         private static native void readOnly(String objectName) /*-{
           if (objectName == null) {
             return;
           }
           
           if ($wnd.document.getElementsByName(objectName) == null) {
             return;
           }	  
           var textField = $wnd.document.getElementsByName(objectName)[0];
         	textField.setAttribute("readOnly","true");
         }-*/;
      but note there is no effect in case you try to set read only if textItem is not rendered

      i use next code to set textItem as read only after a bit of time

      Code:
         private static ArrayList<String> fieldNames = new ArrayList<String>();
      
         private static Timer setReadOnlyTimer = new Timer()
         {
      
            @Override
            public void run()
            {
               for (String fieldName : fieldNames)
               {
                  try
                  {
                     readOnly(fieldName);
                  }
                  catch (Exception exc)
                  {
                     exc.printStackTrace();
                  }
               }
      
               fieldNames.clear();
            }
      
         };
      
         public static void setAsReadOnly(String fieldName)
         {
            fieldNames.add(fieldName);
            setReadOnlyTimer.schedule(500);
         }
      then you use
      Code:
      setAsReadOnly(String fieldName)
      instead

      Comment


        #4
        Setting up read-only property for TextItem

        Originally posted by gavrikvetal
        There is the better way

        Code:
         ...
         readOnly(textItem.getName());
         ...
        
        
           private static native void readOnly(String objectName) /*-{
             if (objectName == null) {
               return;
             }
             
             if ($wnd.document.getElementsByName(objectName) == null) {
               return;
             }	  
             var textField = $wnd.document.getElementsByName(objectName)[0];
           	textField.setAttribute("readOnly","true");
           }-*/;
        but note there is no effect in case you try to set read only if textItem is not rendered

        i use next code to set textItem as read only after a bit of time

        Code:
           private static ArrayList<String> fieldNames = new ArrayList<String>();
        
           private static Timer setReadOnlyTimer = new Timer()
           {
        
              @Override
              public void run()
              {
                 for (String fieldName : fieldNames)
                 {
                    try
                    {
                       readOnly(fieldName);
                    }
                    catch (Exception exc)
                    {
                       exc.printStackTrace();
                    }
                 }
        
                 fieldNames.clear();
              }
        
           };
        
           public static void setAsReadOnly(String fieldName)
           {
              fieldNames.add(fieldName);
              setReadOnlyTimer.schedule(500);
           }
        then you use
        Code:
        setAsReadOnly(String fieldName)
        instead
        Hi,

        Sorry, both of your code is not working in my program.

        Can you tell me, how to set the CSS property of TextItem?

        Can we use
        Code:
        TextItemObject.setTextBoxStyle("read-only: true;");
        or else
        Code:
        TextItemObject.setCellStyle("read-only: true;");
        Thanks,
        Kodan.
        Last edited by kodanhunt; 19 Nov 2009, 08:18.

        Comment


          #5
          i don't understand why they don't work.
          i set property to html tag ( not css style )

          are you have any errors in developer console ?

          Comment


            #6
            Setting up read-only property for TextItem

            Originally posted by gavrikvetal
            i don't understand why they don't work.
            i set property to html tag ( not css style )

            are you have any errors in developer console ?
            No, I'm not getting any exceptions in developers console. But the code is not having any effect.

            Comment


              #7
              You need to redraw the form to see the new visual state:

              Code:
              for (FormItem field : form.getFields()) {
                field.setAttribute("readOnly", true);
              }
              form.markForRedraw();

              Comment


                #8
                I didn't get solution till now for setting a text item as read only. Can anyone please let me know this??

                Comment


                  #9
                  textitem.setAttribute("readOnly","true"); or
                  textitem.setAttribute("readOnly",true);


                  Can you try this and let us know if it still does not have any effect?

                  Comment


                    #10
                    Originally posted by BharathiRajendran
                    textitem.setAttribute("readOnly","true"); or
                    textitem.setAttribute("readOnly",true);


                    Can you try this and let us know if it still does not have any effect?

                    Hi Bharathi Rajendran,

                    Code:
                    textitem.setAttribute("readOnly",true);
                    has worked fine. Thanks alot..

                    Comment


                      #11
                      the textitem.setAttribute("readOnly",true); has worked up to 2.5.
                      With the 3.0 release it doesn't produce any effect.

                      Comment


                        #12
                        Originally posted by bubus_company
                        the textitem.setAttribute("readOnly",true); has worked up to 2.5.
                        With the 3.0 release it doesn't produce any effect.
                        I have the same problem...

                        Comment


                          #13
                          Originally posted by bubus_company
                          the textitem.setAttribute("readOnly",true); has worked up to 2.5.
                          With the 3.0 release it doesn't produce any effect.
                          I found this method from the API:FormItem.setCanEdit(Boolean canEdit)

                          Comment


                            #14
                            Originally posted by LHG
                            I found this method from the API:FormItem.setCanEdit(Boolean canEdit)
                            when the textitem have a icon button ,setCanEdit(false); the icon button disabled
                            any other good idea?

                            Comment


                              #15
                              Originally posted by dr_showtime View Post
                              when the textitem have a icon button ,setCanEdit(false); the icon button disabled
                              any other good idea?
                              I have same problem. Can't make readonly TextItem with Picker icon.

                              Comment

                              Working...
                              X