This is a migrated thread and some comments may be shown as answers.

How to set the Empty Text

3 Answers 300 Views
Application
This is a migrated thread and some comments may be shown as answers.
Anup
Top achievements
Rank 1
Anup asked on 20 Apr 2012, 05:58 PM

For the Application > Form Elements > Text type standard box how does one specify the empty text. This is the text that appears in a standard textbox when do data has been entered. See iOS Contacts application when adding a New Contact the First, Last, Company appear grayed in the first three boxes almost like a watermark. 

This improves the interface as it does not require us to set label text for each textbox and it looks closer to how the native iOS data entry forms work.

3 Answers, 1 is accepted

Sort by
0
Rudá Cunha
Top achievements
Rank 2
answered on 02 May 2012, 07:43 PM
+1
0
Arturo
Top achievements
Rank 1
answered on 02 May 2012, 10:39 PM
I will do something like this 

HTML:
<input  type="text" id="firstName" class="watermark" />

CSS:
.watermark
{
    color: #D3D3D3;
}
  
.unwatermark
{
    color: Black;
}


Javascript:
$('#firstName').text('First Name');
$('#firstName').val('First Name');
$(document).delegate(".watermark", "focus", function (e) {
   if ($(this).val() == $(this).text()){
       $(this).val('');
       var cssClass = $(this).attr('class');
       $(this).attr('class', cssClass.replace("watermark", "unwatermark"));
   }
});
$(document).delegate(".unwatermark", "blur", function (e) {
    e.preventDefault();
    if ($(this).val() == '') {
       $(this).val($(this).text());
       var cssClass = $(this).attr('class');
       $(this).attr('class', cssClass.replace("unwatermark", "watermark"));
   }
});
0
Arturo
Top achievements
Rank 1
answered on 03 May 2012, 07:43 AM
You can also do this:

<input id="firstName" type="text" value="" placeholder="First Name" autocomplete="off" />

The magic key is placeHolder
Tags
Application
Asked by
Anup
Top achievements
Rank 1
Answers by
Rudá Cunha
Top achievements
Rank 2
Arturo
Top achievements
Rank 1
Share this question
or