James,

Maybe it is a question of timing?

When I hard-coded class="required" on the input fields I received the
desired effect. However, I want to get this effect based on business
rules on my object model.

Version 1.3.2 that comes as part of the asp.net mvc releases does not
contain any changes to the code. Something I forgot to mention (did
more research) and the xVal code adds the class="required" attribute
via the addClass method to the input field at runtime based on jQuery
validation (addon?) rules. I have verified using Firebug that the
class is being applied to the elements correctly.

Baum


On Apr 3, 1:16 pm, Baum <dbau56...@gmail.com> wrote:
> No. This is my first project with jQuery. I used your (James, March
> 31) code directly and that is the only jQuery call used in the entire
> site. I happened to have some asp.net MVC samples that used 1.2.6 and
> I switched the reference to use the 1.2.6 version and the code worked
> as expected.
>
> I will try to download 1.3.2 from the jQuery.com.
>
> Thanks,
>
> Baum
>
> On Apr 1, 5:54 pm, James <james.gp....@gmail.com> wrote:
>
> > I'm not sure what the asp.net MVC release of jquery is and if it's
> > been modified from the original, but on my 1.3.2 (from jquery.com),
> > the code works. So there is no problem with jQuery 1.3.2 regarding each
> > ().
> > There must be something else that's causing the issue. Do you still
> > have somewhere in your code the deprecated syntax with the @ in the
> > selectors?
> > Eg. $("inp...@type=text]")
>
> > On Mar 31, 5:51 pm,Baum<dbau56...@gmail.com> wrote:
>
> > > Thanks James.
>
> > > I am just getting started with jQuery so the syntax is rather new.
> > > What I found is that the jquery-1.3.2.js file that I am using as part
> > > of the asp.net MVC release does not appear to work with each syntax (I
> > > only get the first input field back). I reverted back to 1.2.6 and it
> > > appears to work.
>
> > > This leads me to believe there is a problem with 1.3.2...
>
> > >Baum
>
> > > On Mar 31, 9:04 pm, James <james.gp....@gmail.com> wrote:
>
> > > > How about something like:
>
> > > > $required = $(".required"); // list of elements with 'required' class.
> > > > $.each($required, function(i) {
> > > >      var id = $(this).attr('id');
> > > >      var $label = $("label[for="+id+"]");
> > > >      $label.text( $label.text()+'*' );
>
> > > > });
>
> > > > The requirement is that all your .required input's ID should have a
> > > > corresponding label with a matching 'for' ID. (It's not going to bomb
> > > > or anything if it doesn't.)
>
> > > > On Mar 31, 3:46 pm,Baum<dbau56...@gmail.com> wrote:
>
> > > > > One note the javascript included in the original post is incorrect...I
> > > > > was playing around and pasted the wrong copy...remove the each(). Also
> > > > > var size = $(".required").size(); is equal to 1 but var size = $
> > > > > ("input").size(); is equal to 2.
>
> > > > > Thanks.
>
> > > > > On Mar 31, 7:56 pm,Baum<dbau56...@gmail.com> wrote:
>
> > > > > > Hi,
>
> > > > > > I am looking to use jQuery in conjunction with xVal for validation.
> > > > > > One of the cool things I though jQuery would allow me to do is 
> > > > > > append
> > > > > > an asterisk (*) to the label of "ALL" my fields that have a css 
> > > > > > class
> > > > > > of "required". The example below only applies the asterisk to the
> > > > > > first field.
>
> > > > > > How can I get all of the fields from my page that have a
> > > > > > class="required", find the label (previous element) for each, and
> > > > > > append some text (an asterisk) to the label for that field?
>
> > > > > > Example
> > > > > > ======================
>
> > > > > > <script type="text/javascript">
> > > > > > $(document).ready(function() {
> > > > > >            //$('label.required').append('&nbsp;<strong>*</
> > > > > > strong>&nbsp;');
> > > > > >            $(".required").each().prev().not('input').not('br').not
> > > > > > ('select').append(' * ');
> > > > > >        });
> > > > > > </script>
>
> > > > > > <label for="FirstName'>LastName</label>
> > > > > > <input id="FirstName" class="required" />
>
> > > > > > <label for="LastName">LastName</label>
> > > > > > <input id="LastName" class="required" />
>
> > > > > > Thanks,
>
> > > > > >Baum

Reply via email to