You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Girish Naik <gi...@gmail.com> on 2009/05/29 20:00:44 UTC

How to make readonly textfield in Struts 2.0.11.2 datetimepicker

Hi,
I have used struts2-core-2.0.11.2 in My Application. And intend to use the
Struts date time picker, but the text field is coming as an editable field.
I want to make it as a readonly textbox. The funny thing  is that the dojo
is not ready to pass my id to the textbox. Only name is supplied to the text
box.

Any suggesstions on how to make the textbox non editable and only the icon
clickable?

Thanks in Advance.


Regards,
---------------------------------------------------------
Girish Naik
Mobile:-+91-09740091638
girish.naik@gmail.com
Mitch Hedberg<http://www.brainyquote.com/quotes/authors/m/mitch_hedberg.html>
- "My fake plants died because I did not pretend to water them."

Re: How to make readonly textfield in Struts 2.0.11.2 datetimepicker

Posted by Bharath Kumar <bh...@gmail.com>.
Hi Guys :),
   I too googled for many hours for this and didnt find any solution, so i
tried to do it myself and it worked out luckly :)

In my case i hve this datetimepicker in a TD
--------------------------------------------
<td onkeydown="Javascript:disablekeys();"
onmousedown="Javascript:disableControls()">
	<sx:datetimepicker id="startDate" name="startDate"></sx:datetimepicker>
</td>
--------------------------------------------

This is the outerHTML of the datetimepicker when it renders 
-----------------------------------------------------------
This is document.getElementById('startDate').outerHTML;

<input type=hidden value=2009-06-11 name="" dojoAttachPoint="valueNode">
<input value=6/11/2009 name="" __doClobber__="true"
dojoAttachPoint="inputNode">
 <imag alt="Select a date" src="../images/dateIcon.gif" __doClobber__="true"
dojoAttachPoint="buttonNode" dojoAttachEvent="onclick:onIconClick"> 
---------------------------------------------------------------

So the solution i found out is 
------------------------------
<script languae="javascript">
function disableControls(){
document.getElementById('startDate').childNodes[1].disable='true';
document.getElementById('startDate').childNodes[1].readOnly='readonly';
document.getElementById('startDate').childNodes[1].disable='';
}
function disableKeys(){
	var keyCode=(document.all)?event.keyCode:e.which;
	if(keyCode==9){
		window.event.returnValue=true; //for allowing TAB
	}else{
		window.event.returnValue=false;
	}
}
</script>
------------------------------

Note* -This will work unless and untill struts framework dont change the
order of the childNode.

Thanks
Bharath


Girish Naik wrote:
> 
> Hi,
> I have used struts2-core-2.0.11.2 in My Application. And intend to use the
> Struts date time picker, but the text field is coming as an editable
> field.
> I want to make it as a readonly textbox. The funny thing  is that the dojo
> is not ready to pass my id to the textbox. Only name is supplied to the
> text
> box.
> 
> Any suggesstions on how to make the textbox non editable and only the icon
> clickable?
> 
> Thanks in Advance.
> 
> 
> Regards,
> ---------------------------------------------------------
> Girish Naik
> Mobile:-+91-09740091638
> girish.naik@gmail.com
> Mitch
> Hedberg<http://www.brainyquote.com/quotes/authors/m/mitch_hedberg.html>
> - "My fake plants died because I did not pretend to water them."
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-make-readonly-textfield-in-Struts-2.0.11.2-datetimepicker-tp23784592p24010121.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to make readonly textfield in Struts 2.0.11.2 datetimepicker

Posted by Girish Naik <gi...@gmail.com>.
I have achieved this by use of JavaScript as follows:

....
....

//2009-06-05T00:00:00
    var validDate =
/^([\d]{4})-([\d]{2})-([\d]{2})T([\d]{2})\:([\d]{2})\:([\d]{2})$/i;
    var elements = document.getElementsByName('dateOfBirth');
    for(var i = 0; i < elements.length; i++){
        //alert('element:'+i +' element.value:'+ elements[i].value);
        if(!(validDate.test(elements[i].value))){
//here i am showing a error message, you can alert also.

document.getElementById('registration_error_date_of_birth_required').style.display
= "";
            isError = 1;
        }
        if(isError){
            break;
        }
    }
...
...


This function is called on submit of the form.

But i would like to know if there is a way in Struts to control the user
entry in the textbox.

Regards,
---------------------------------------------------------
Girish Naik
Mobile:-+91-09740091638
girish.naik@gmail.com
W. C. Fields <http://www.brainyquote.com/quotes/authors/w/w_c_fields.html>
- "I am free of all prejudices. I hate every one equally."

On Sat, May 30, 2009 at 11:28 AM, Girish Naik <gi...@gmail.com> wrote:

> There is no readonly attribute in s:datetimepicker tag. I am using the
> following tag
>
> <s:datetimepicker     id="registration_date_of_birth_field"
>                             name="dateOfBirth"
>                             labelposition="left"
>                             type="date" toggleDuration="2000"
> toggleType="fade" disabled="true"
>                             required="true"
>                             displayFormat="yyyy-MM-dd'T'HH:mm:ss"
>                             weekStartsOn="1"  />
>
>
> PFA for the rendered UI for the above tag.
>
>
> Regards,
> ---------------------------------------------------------
> Girish Naik
> Mobile:-+91-09740091638
> girish.naik@gmail.com
> Frank Lloyd Wright<http://www.brainyquote.com/quotes/authors/f/frank_lloyd_wright.html> - "TV is chewing gum for the eyes."
>
> On Fri, May 29, 2009 at 11:37 PM, Jim Collings <jl...@gmail.com>wrote:
>
>> I just did this a while ago. All I had to do was set:
>>
>> readonly="true"
>>
>> on the struts textfield tag. Mine doesn't have an icon though.
>>
>> On Fri, May 29, 2009 at 2:00 PM, Girish Naik <gi...@gmail.com>
>> wrote:
>> > Hi,
>> > I have used struts2-core-2.0.11.2 in My Application. And intend to use
>> the
>> > Struts date time picker, but the text field is coming as an editable
>> field.
>> > I want to make it as a readonly textbox. The funny thing  is that the
>> dojo
>> > is not ready to pass my id to the textbox. Only name is supplied to the
>> text
>> > box.
>> >
>> > Any suggesstions on how to make the textbox non editable and only the
>> icon
>> > clickable?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>

Re: How to make readonly textfield in Struts 2.0.11.2 datetimepicker

Posted by Girish Naik <gi...@gmail.com>.
There is no readonly attribute in s:datetimepicker tag. I am using the
following tag

<s:datetimepicker     id="registration_date_of_birth_field"
                            name="dateOfBirth"
                            labelposition="left"
                            type="date" toggleDuration="2000"
toggleType="fade" disabled="true"
                            required="true"
                            displayFormat="yyyy-MM-dd'T'HH:mm:ss"
                            weekStartsOn="1"  />


PFA for the rendered UI for the above tag.


Regards,
---------------------------------------------------------
Girish Naik
Mobile:-+91-09740091638
girish.naik@gmail.com
Frank Lloyd Wright<http://www.brainyquote.com/quotes/authors/f/frank_lloyd_wright.html>
- "TV is chewing gum for the eyes."

On Fri, May 29, 2009 at 11:37 PM, Jim Collings <jl...@gmail.com> wrote:

> I just did this a while ago. All I had to do was set:
>
> readonly="true"
>
> on the struts textfield tag. Mine doesn't have an icon though.
>
> On Fri, May 29, 2009 at 2:00 PM, Girish Naik <gi...@gmail.com>
> wrote:
> > Hi,
> > I have used struts2-core-2.0.11.2 in My Application. And intend to use
> the
> > Struts date time picker, but the text field is coming as an editable
> field.
> > I want to make it as a readonly textbox. The funny thing  is that the
> dojo
> > is not ready to pass my id to the textbox. Only name is supplied to the
> text
> > box.
> >
> > Any suggesstions on how to make the textbox non editable and only the
> icon
> > clickable?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: How to make readonly textfield in Struts 2.0.11.2 datetimepicker

Posted by Jim Collings <jl...@gmail.com>.
I just did this a while ago. All I had to do was set:

readonly="true"

on the struts textfield tag. Mine doesn't have an icon though.

On Fri, May 29, 2009 at 2:00 PM, Girish Naik <gi...@gmail.com> wrote:
> Hi,
> I have used struts2-core-2.0.11.2 in My Application. And intend to use the
> Struts date time picker, but the text field is coming as an editable field.
> I want to make it as a readonly textbox. The funny thing  is that the dojo
> is not ready to pass my id to the textbox. Only name is supplied to the text
> box.
>
> Any suggesstions on how to make the textbox non editable and only the icon
> clickable?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org