We want to adjust all label-tags from a jquery mobile form with the with from the largest label. Here one codesample for one field:
... <fieldset data-role="fieldcontain">
<label for="fusrName">Benutzername/E-Mail<b class="kontoman-mandatory">*</b></label>
<input id="fusrName" name="fusrName" type="text" placeholder="Benutzername/E-Mail" value="">
</fieldset>...
This is the jquery function:
$.fn.labelWidth = function () {
var maxWidth = 0;
$('fieldset').each(function() {
$(this).find('label').each(function() {
var width = $(this).width();
if (width > maxWidth) {
maxWidth = width;
}
});
});
$('fieldset').each(function() {
$(this).find('label').each(function() {
$(this).css({width:maxWidth});
});
});
}
... and this is the function-call:
$(document).on('pageshow',function(event,ui) {
$('#kontoman-form').labelWidth();
If we debug: Into the variable maxWith we have the right width ...but the form dosn't change? What is our mistake?
You were close but not close enough. Your plugin is made on assumption that every label has a separate width and that is not correct. Label has always 20% width, input has 78% width and there's a margin of 2% between them.
Working example: http://jsfiddle.net/Gajotres/mMmcP/
You changed plugin code:
One other plugin is important for this plugin to work, it can be found here. I am not a second plugin developer.
Here's a second plugin: