Providing Required Format Information in Text Box in MVC view - asp.net-mvc

How do you set a string to denote the required format pattern in a text box. For instance, if I have a text box displayed such as a date field, how do I display a format of "dd/mm/yyyy" to help the User complete the field. If the field is already populated when the view is displayed then the actual data should be displayed.
If the field is a drop down list, I would like to display "Please select from the list" if the field does not contain a value.

In HTML 5 you can achieve it using Placeholder attribute of input tag like this:
<input name="email" type="email" placeholder="validemail#email.com" />
However HTML5 is not yet supported by most browsers, so you will have to live with javascript based solution. Populate the desired value in textbox when page is loading (you can use CSS to make that text dim). Using javascript empty the field on "onfocus" event.
For drop down list populate "please select..." thing with Value as 0. This way you can validate on server that user has not selected any valid value.

Related

How to hide a field in editable mode in grails application using .gsp file?

I have a situation in my application where I need to hide a field in one editable mode, but be visible and editable in another editable mode. For instance, I have ownerEdit where it renders a file _userid.gsp and all fields in the _userid.gsp are editable. At the same time, I am trying to render _userid.gsp file in userEdit mode where I need to hide some fields completely.
Any suggestions are welcome. Here are the sample codes:
I have ownerdataEdit.gsp which is call in ownerEdit.gsp. The _ownerDataEdit.gsp indeed call _userid.gsp as
<g:render template = "userid" model="${[userEditable:!ownerView.equals('show')]}"/>
Similarly, userDataEdit.gsp also call _userid.gsp as
<g:render template = "userid" model="${[userEditable:userEdit]}"/>
And finally, the _userid.gsp has codes for the password field which I want to hide. And to do that I used if statement
<g:if test="${[userEdit:true]}"><dt input type="hidden"</dt></g:if>
<g:else>render the field </g:else>
For some reason it doesn't seem to be reading g:if condition.
You will need to pass the mode in the render model:
render(template: "userid", model: [editable: true])
Then you have some options.
You could take the trivial route and use style='display: none' on fields when editable is true. This has the added benefit of being able to easily toggle between editable and not client-side, if that has value to you.
You could use <input type='hidden' ... /> fields if you need the values to come through to any submission. Note that these can still be edited by a user who knows how to use the developer console, so you'll need to have protections in place on your server side as well to prevent malicious editing.
You could just not render the fields at all when you're not in editable mode, if you don't need them for anything.
Additional info:
Change your if conditions from:
<g:if test="${[userEdit:true]}"><dt input type="hidden"</dt></g:if>
to:
<g:if test="${userEditable}"><dt input type="hidden"</dt></g:if>

Can I mark a template field in MediaWiki in a way that it only shows when no value is filled?

I'm editing the Wikimedia template for {{Property Proposal}} on Wikidata.
When there's no example filled in the template the template says "missing".
This is achieved by having the field marked with "required = true,"
I would like to have a similar message on the "|subpage = ?" when that field is missing, however I don't want it to show anything when the field is filled (then the content of the field shouldn't be visible to the user.
Is there a way to get this outcome?

Including Empty Text in TFS HTML Field (TFS 2013)

I am trying to add default empty text to an HTML field in TFS 2013. I am doing this by updating the "EmptyText" attribute for the field in the Layout options (using Process Editor).
However, regardless of what I enter here, the intended text is never displayed. It is always empty. I have the same issue with both HTML & Plain Text fields.
Is this a fundamental limitation of TFS? Or am I specifying this incorrectly?
I am not using a DEFAULT rule because I want the user to notice that the field is empty and be required to enter a value.
I can get it work correctly. Two changes made:
Edit the "Empty Text" attribute just as you mentioned above (in my case I create one custom HTML field called Custom.DetailHTML):
Add Required rule to this field to define that this field must be specified with a value:
<FieldDefinition name="DetailHtml" refname="Custom.DetailHtml" type="HTML">
<REQUIRED />
</FieldDefinition>
If you still can't get it work, please show your WIT file.

Grails formRemote disabled field content isn't coming back as a param from GSP

I am showing a text field on a GSP template that is in a formRemote and has content auto populated and is disabled (no editing allowed to user). When the form is submitted, I don't see the content of this field among the params going to the controller. I do see it when I remove the disabled="true" attribute from the text field. Any way to resolve this? Here is the field in question:
<label>Secondary ID:</label>&nbsp<g:textField name="secondaryId" disabled="true" style="border-radius: 5px" value="${recordToEdit ? recordToEdit.secondaryId : '' }"></g:textField>
Disabled form elements do not get submitted by the browser. You will need to enable the field(s) (through use of Javascript) prior to submitting the form.

HTML5 Mobile Safari DatePicker - Initial Value

We're working on a .NET MVC mobile site. I understand that on the iPhone, mobile safari will display a datepicker for the following input field:
<input type="date"/>
We have a standard date picker helper which spits out date picker options for various platforms. In this case we detect mobile safari and then write out an input field that is bound to our model:
<input name="StartDate" value="2008/12/21" type="date"/>
The problem is that the value portion is not shown on load. We can enter in new values, and save them back to our database. But then when we reload the page those values don't show up in the fields. If we save again, our values are all set back to null in the db.
I noticed that when you select a date with the wheels on the iPhone, the value of the text field ends up in the format similar to "Apr 6, 2012" where as I'd expect it to show 2012/04/06 or 04/06/2012.
My guess is that the mobile safari displays a different attribute of the field, and then sets the value attribute appropriately behind the scenes.
Does anyone know what's going on with this? Thanks!
AFAIK the date must be RFC3339 compliant. Have you tried 2008-12-21 (dashed instead of slashes)?
<input type="date" value"yyyy-MM-dd" />

Resources