Labels inside form fields with added Infield Top Aligned Labels - css

I'm looking to update our website and have the checkout form fields using labels inside the fields. I've read on various blogs this simple idea has some downfalls, such as the user forgetting what he/she was typing in that box in the first place.
So I stumbled across firebox.com checkout, which also uses infield top aligned labels, nullifying the above problem. Also, on input, there are regular labels inside the field.
Has this idea/solution been previously documented? I would prefer not to go through the source code of this site if there is a working example out there already!
Here is a screenshot of what I'm looking to do, some fields have been inputted already to show the result before and after.

Google Material design is what I think you are looking specially the part of the text fields.
No need to look through the code:
https://material.io/guidelines/components/text-fields.html#
Here you can see all available options:
https://getmdl.io/components/index.html#textfields-section
Hope it helps,
André

What You are looking at is a sample of Google's Material Design components. The material design framework is meant to be part of AngularJS , but there are multiple CSS ways of achieving the same effects.
Here You can find a variant for Your task at hand.
And it uses generic markup:
<form>
<h1>Material Design Text Input With No Extra Markup</h1>
<input placeholder="Username" type="text" required="">
<input placeholder="Password" type="password" required="">
<button>Submit</button>
</form>

Related

How to add checkmarks and x's when validating in angularjs?

I couldn't find anything in the angularjs docs, nor online, about this specific aspect of form validation. You know when someone writes something in an input field (example: name, phone number, email etc.), and then there is a green checkmark that appears? Or an X that appears implying it's wrong, incomplete etc.
So, I have those images in my folder and ready for use in either situation. Problem is, I can't find the documentation to properly achieve what I would like to achieve. I am thinking that angularjs would be the solution to use, as the rest of my code in is angular.
Since this is angularjs, the only post and documentation that presented a viable option (which does not work for a few reasons) are the following options:
How to put an image in div with CSS?
https://docs.angularjs.org/tutorial/step_09
I was thinking of using CSS to trick the browser into making the one or the other image appear as it validates. I thought it might force the image in my other div to appear, but to no avail.
For example, in this CSS, I tried this:
.ng-valid.ng-dirty .div.test{
border-color: green;
content:url(http://example.com/image);
}
Using this in my HTML:
<div class="test">
<label style="float:left">by:</label>
<input class="form-control controltwo" required ng-model="reviewCtrl.review.author" name="email" id="email" type="email" style="width:350px;" placeholder="Email Address"/>
</div>
As I said before, I am trying to achieve something using angularjs. As CSS can be used for styling, it cannot be tricked into being a styling option and a complex validator. I've tried a few tricks as show on the links, but they don't work. As for the second link, it just isn't made for this purpose, and considering they are made only for filters and images, the docs for the filters don't help a bit.
A simple way of achieving what you want is to look in to the $valid or $invalid properties of your form control.
For example, to show a small message when the email is invalid, you would put this element in your markup.
<div ng-show='reviewForm.email.$dirty && reviewForm.email.$invalid'>Invalid Email</div>
Where reviewForm is the name of your form, and email is the name of your input control.
Here is a plunkr demonstrating this: http://plnkr.co/edit/tUuToy99xjfMhbyMd3eV
You can replace the element with whatever else you want
You can do this with ng-show, ng-src and ng-model depending on what you're validating.
https://docs.angularjs.org/api/ng/directive/ngModel
https://docs.angularjs.org/api/ng/directive/ngShow
https://docs.angularjs.org/api/ng/directive/ngSrc
The example under ng-model:text shows pretty much what you want. If you're not using forms, you should be able to use ng-change to fire off a check and change the image to the appropriate one.
https://docs.angularjs.org/api/ng/input/input%5Btext%5D
If ng-show watches the $valid attribute of the field in question you can hide the check mark when validation is false, and show it when true. You can flip the logic if you want an X.

HTML 5 Placeholder: when user selects field make text disappear

Is this possible to achieve without javascript/jQuery?
I currently have a login template with the input fields as:
<input id="username" type="text" name"username" placeholder="username" autofocus>
I was wondering if there was a way when the user clicked their mouse on the field to type the placeholder text would disappear without using javascript if possible? Before this i was just using value and echoing the variables out into the fields but currently experimenting with HTML 5 and CSS3.
Thanks.
New browsers have a native way to do this. And if supported, you don't have to do anything.
With older browsers you do need to use javascript.
Edit: When using new features on old browsers its called Pollyfills. Here is a nice list with a lot of pollyfills that can be used together with Modernizer, that in turn can detect this features.

Drupal views - splitting up the exposed form possible?

I need to display part of the exposed form in my page's sidebar, and the rest of the form and content in the $content area. There's really no good way that I can find to do this. I sort of got it to show up in a way by making a "block" view with "exposed form" set and then trying to only show the part that i needed through .tpl files. The problem is that then, when the submit button is clicked (the submit button is in the $content area), then the filters that are in the sidebar are not taken into account.
Some lateral thinking... Why not explore CSS-only options? You can place that form element playing with position:absolute ? Or (considering is a right-sidebar) float:right and then some negative right margin to push it to the sidebar? If you are using 960 grid system, play with pull and push classes.
First I am going to answer your question, then I will explain why you are asking the wrong question:
If you build the form outside of the formapi, you might have some luck. This will get upgly and will require you to take a lot of extra care about attack-vectors such as mass-assignment.
views_some_view.tpl.php:
<form name="input" action="/link/to/view" method="get">
Country: <input type="text" name="country" />
my_custom_exposed_view.module:hook_block()
City:
That would make a form, which in most situations will start with <form>, have some input fields, then have a lot of random HTML, then some more input fields and then the closing .
As you may know, a <input type="submit" value="Submit" /> will only post everything of the form tags it is enclosed in. The submit button in the following HTML:
<form name="input_1" action="/link/to/view" method="get">
Country: <input type="text" name="country" />
</form>
<form name="input_2" action="/link/to/view" method="get">
City: <input type="text" name="city" />
<input type="submit" value="Submit" />
</form>
will only send the City. These are not the droids you are looking for.
It will need to be one, big form, but since everything between form and /form is very dynamic, and contains a large quantity of HTML, including potential other forms, this is really not what you want. Moreover: a blocks appearance (shown/not-shown) is controlled completely independent of the content. You will need a lot of sturdy code to ensure the block a) never shows up when the starting form tag is not present, and b) the block will guaranteed to be shown when that opening form tag is present. Else you have not just invalid HTML, but broken HTML that will truly render your page unusable in most cases.
You simply don't want a part of the form in a block and the other part in the content.
However, you want it visualised as if one part is in the body, the rest in a sidebar.
The good news, is that with HTML presentation structure are independant. That is where your solution lies.
Give your form-fields good ids and classes. You could use a hook_form_alter to change existing forms, but you probably simply just want to create the HTML for that entire form yourself. The theme layer allows that.
Use CSS to pick out either single form-fields by ID and position:absolute them into the correct place. Or pick out classes of fields by CLASS and position:relative them into the correct place.
Make a simple identification-routine that allows adding a class to the body-tag. (see below).
Add some CSS to shift the sidebar lower, making space for the form-fields to be moved in, when that class is in the body-tag.
<body class="<?php print $splitform ?>">
function my_themename_preprocess_page() {
if ($GET['q'] == 'path/to/view') {
$vars['spliform'] = "splitform"
}
}
From the above explanation I am assuming that you are printing same form in block and in content area and you are hiding some part of form in page.tpl , if this is true then you can use hook_form_alter() in your custom module then
Store the value of the form element(present in block) in global variable.
Now use that global variable and set form element(present in content area, this form element is not visible to user).
Provide more information if you implemented other way.
Regards,
Chintan.
There is a related issue here:
https://drupal.stackexchange.com/questions/3827/multiple-copies-of-views-filter-form-exposed-filters
which describes how to duplicate your filters. However it seems like an ugly hack.
A bit cleaner seems this solution mentioned in #6:
http://drupal.org/node/641838#comment-3247748
Haven't tested it out, but it looks good.
It will still give you some overhead (duplicate views) but it might be the easiest way doing this using views.
On the other hand you might write a module and build your own custom filter block which hooks into your view. Here is a blog post about this:
http://www.hashbangcode.com/blog/creating-custom-views-filters-exposed-form-element-drupal-6-561.html
If you use something like context you could get the exposed filters block to display twice in the same page. You could then use CSS to hide the fields you don't want to do display in each form.
The fundamental problem you're having is that to have the two forms in different places, they'll each have their own form element - when a submit is triggered, only the form fields within the same form element are sent. You need to move them into one form, or rely on JavaScript to gather the fields from both forms and construct the post.
You could create the block as an empty div and have javascript from the main page populate it with the secondary filter form and whatever else you need in there. Again, you could use javascript to copy the form values from the block form to hidden fields in the main form on submit. That gives you all the control you need from one place (the node output). Only caveat is that it relies a lot more on javascript to join it all together.

creating multicolumn forms

I am planning to build a multicolumn form with atleast 5 to 6 fields.
What would be the best approach of doing this using CSS floats? or using tables with css. Since the form is going to be pretty long atleast around 50 rows.
It could have check boxes, radio , just text and input boxes. Any sample or examples out there? or any tools that can be used to make it on the fly( not looking for dream weaver or of similiar type)
here is the sample layout of the form how it going to be:
Fieldname1 ,Fieldname2 ,Fieldname3 ,Fieldname4 ,Fieldname5
inputbox1(checkbox), text, inputbox3, inputbox4, inputbox5
Thanks
If you're generating the page dynamically, it's easy to use libraries to generate the form algorithmically from within the programming language you're using. For example, deform in Python. This basically saves you the trouble of writing fifty rows' worth of HTML on your own.
Alternately, you can use a JavaScript library like jQuery to add rows within the user interface (with a button like "add another entry").
You can use tables or CSS; your decision here doesn't really matter. Tables are going to be less complex conceptually, and so would be my first choice, but if you want to add rows dynamically, different browsers can behave unpredictably because tables don't always behave nicely when you manipulate them after the initial page load.
separate the columns in <fieldset> tags then give them a fixed width and float them.
Here is an example:
HTML
<form>
<fieldset>
<input />
<input />
</fieldset>
<fieldset>
<input />
<input />
</fieldset>
</form>
CSS
form { width:100% }
fieldset { width:25%; float:left }
I think, you need some program, that will help you to build a personalized form.
Try php forms, it will be easy for you to work in this program because it has a video, that fully describes the process of form creation.

(Custom) WAI-ARIA role

I'm pretty new to ARIA and the roles, states, and properties it provides. I understand that there are different types of roles (e.g. landmarks, regions, etc) but none of them represent areas like "login region" or something similar. I wonder if there are ways to specify the grouping of this information so that the screen reader can read out this information for the users? E.g. "Login region. User name ... Password ..."
If this is not possible with ARIA, what is the general way of doing it in HTML?
Thanks in advance
WAI-ARIA is generally for dynamic content, like a news headline ticker, and not for static content, like a login form. Static content is best achieved using plain HTML.
Assuming you have a page where the login form is always displayed, the following should help.
For a login form, from an accessibility point of view, you should primarily ensure that the form fields are correctly labelled. A fieldset\legend is really optional for such as small form.
Coding labels up correctly means using matching for\id attributes e.g.
<label for="loginName">Login name</label>
<input type="text" id="loginName" name="loginName" size="30" />
<label for="loginPassword">Login password</label>
<input type="password" id="loginPassword" name="loginPassword" size="10" />
This ensures that screenreader (blind) users can properly hear the form fields corresponding label read out. For other form elements, such as checkboxes and radio buttons, using correct labelling like this allows users with dexterity issues to click on the text label to toggle the form input (checkbox\radio button), meaning they have larger target area to click on the page.
To let the user know they were about to access a login form, you could use either a heading, or the fieldset\legendf combo e.g.
<h2>Login form</h2>
<FORM HERE>
Or
<fieldset>
<legend>Login form</legend>
<FORM HERE>
</fieldset>
Either of these would be fine, although the heading approach would create slightly less audio clutter for screenreader users (WIth a fieldset\legend, the legend is read out before each form field)
Yes and no. The form should be given a landmark role of "form". This allows the assistive technology to see the landmark for navigation purposes.
Refer to the spec.
While using the landmark will aid in navigating the page, the landmark itself won't produce the reading of the items in the form itself. Following the already known HTML practices mentioned will take care of the rest.

Resources