Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » ModelForm Field not display choice text [RSS Feed]

#1 Dec. 27, 2010 11:39:30

Michael T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

ModelForm Field not display choice text


Hi,
I am using the jQuery stars on a radio field as a custom renderer. The
stars come up nicely but the
choice text still displays to the side of the stars.
How can I not show the choice text but still populate the field with
the choice result?
I am displaying the field in the template like this:
{{ userForm.fitStars }}

BTW - I am not talking about the label text. For example,
How was your meal?

But rather the radio button choices.

The radio button text I want to not display.

Thanks
Michael

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 27, 2010 11:48:45

Michael T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

ModelForm Field not display choice text


One thought, and this maybe the whole issue, is that the radio button
is using labels for the text and not titles.
I would expect the output to be something like this:
<input type="radio" name="newrate" value="1" title="Very poor" />
but instead the output is like this:
<label for "newrate">
<input type="radio" name="newrate" value="1" />
1
</label>

Is this something that anyone else has had to deal with?

Thanks
Michael

On Dec 27, 6:39 am, Michael Thamm <webmas...@morningcat.com> wrote:
> Hi,
> I am using the jQuery stars on a radio field as a custom renderer. The
> stars come up nicely but the
> choice text still displays to the side of the stars.
> How can I not show the choice text but still populate the field with
> the choice result?
> I am displaying the field in the template like this:
> {{ userForm.fitStars }}
>
> BTW - I am not talking about the label text. For example,
> How was your meal?
>
> But rather the radio button choices.
>
> The radio button text I want to not display.
>
> Thanks
> Michael

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 27, 2010 14:16:40

Chris L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

ModelForm Field not display choice text


Michael,

In one of my projects, I did something like this:

<form id='stars' action='/some/url' method='post'>
{% for field in rating_form %}
<li>{{ field}}</li>
{% endfor %}
<li><input type='submit' value='Rate'/></li>
</form>

$('#stars').children().not(":radio").hide()
$('#stars').stars({
cancelShow: false,
callback: function(ui, type, value){
ajaxVote(value);
}
});

function ajaxVote(value) {
$.ajax({ url: '{% url plugin-rate object.slug %}',
type: 'POST',
data: { rating: value },
dataType: 'json',
success: function(data){
var avg_rating = data
var votes = data
$('#rating_display').html(avg_rating +" out of 5 (Rated " +
votes + " times)")
},
});
}

The key to hiding the other form elements (like the labels) is the $
('#stars').children().not(":radio").hide() call, which basically hides
everything but the actual stars. If the use doesn't have JS enabled,
they should still see the radio buttons with the associated labels.

Hope that helps,

Chris

On Dec 27, 6:48 am, Michael Thamm <webmas...@morningcat.com> wrote:
> One thought, and this maybe the whole issue, is that the radio button
> is using labels for the text and not titles.
> I would expect the output to be something like this:
> <input type="radio" name="newrate" value="1" title="Very poor" />
> but instead the output is like this:
> <label for "newrate">
>     <input type="radio" name="newrate" value="1" />
>   1
> </label>
>
> Is this something that anyone else has had to deal with?
>
> Thanks
> Michael
>
> On Dec 27, 6:39 am, Michael Thamm <webmas...@morningcat.com> wrote:
>
>
>
>
>
>
>
> > Hi,
> > I am using the jQuery stars on a radio field as a custom renderer. The
> > stars come up nicely but the
> > choice text still displays to the side of the stars.
> > How can I not show the choice text but still populate the field with
> > the choice result?
> > I am displaying the field in the template like this:
> > {{ userForm.fitStars }}
>
> > BTW - I am not talking about the label text. For example,
> > How was your meal?
>
> > But rather the radio button choices.
>
> > The radio button text I want to not display.
>
> > Thanks
> > Michael

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Dec. 27, 2010 14:27:18

Michael T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

ModelForm Field not display choice text


Thanks very much - that does help.
I'm surprised it has to be done in jquery.
But if it works, I'm all for it.
Thanks again.


On Dec 27, 9:16 am, Chris Lawlor <lawlor.ch...@gmail.com> wrote:
> Michael,
>
> In one of my projects, I did something like this:
>
> <form id='stars' action='/some/url' method='post'>
>     {% for field in rating_form %}
>         <li>{{ field}}</li>
>     {% endfor %}
>     <li><input type='submit' value='Rate'/></li>
> </form>
>
> $('#stars').children().not(":radio").hide()
>     $('#stars').stars({
>         cancelShow: false,
>         callback: function(ui, type, value){
>             ajaxVote(value);
>         }
>     });
>
> function ajaxVote(value) {
>         $.ajax({ url: '{% url plugin-rate object.slug %}',
>                  type: 'POST',
>                  data: { rating: value },
>                  dataType: 'json',
>                  success: function(data){
>                     var avg_rating = data
>                     var votes = data
>                     $('#rating_display').html(avg_rating +" out of 5 (Rated "
> +
> votes + " times)")
>                  },
>         });
>     }
>
> The key to hiding the other form elements (like the labels) is the $
> ('#stars').children().not(":radio").hide() call, which basically hides
> everything but the actual stars. If the use doesn't have JS enabled,
> they should still see the radio buttons with the associated labels.
>
> Hope that helps,
>
> Chris
>
> On Dec 27, 6:48 am, Michael Thamm <webmas...@morningcat.com> wrote:
>
> > One thought, and this maybe the whole issue, is that the radio button
> > is using labels for the text and not titles.
> > I would expect the output to be something like this:
> > <input type="radio" name="newrate" value="1" title="Very poor" />
> > but instead the output is like this:
> > <label for "newrate">
> >     <input type="radio" name="newrate" value="1" />
> >   1
> > </label>
>
> > Is this something that anyone else has had to deal with?
>
> > Thanks
> > Michael
>
> > On Dec 27, 6:39 am, Michael Thamm <webmas...@morningcat.com> wrote:
>
> > > Hi,
> > > I am using the jQuery stars on a radio field as a custom renderer. The
> > > stars come up nicely but the
> > > choice text still displays to the side of the stars.
> > > How can I not show the choice text but still populate the field with
> > > the choice result?
> > > I am displaying the field in the template like this:
> > > {{ userForm.fitStars }}
>
> > > BTW - I am not talking about the label text. For example,
> > > How was your meal?
>
> > > But rather the radio button choices.
>
> > > The radio button text I want to not display.
>
> > > Thanks
> > > Michael

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » ModelForm Field not display choice text [RSS Feed]

Board footer

Moderator control

Enjoy the 21st of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support