logo
down
shadow

Customizing Radio buttons in Django


Customizing Radio buttons in Django

By : GaijinGuyJim
Date : November 22 2020, 10:48 AM
Hope this helps How do I create a radio button form with custom radio buttons in Django? , you should do like this, hope this will work for you.
code :
from django import forms

TEST_TYPE_CHOICES = [
('HDFS', 'HDFS'),
('HIVE', 'HIVE'),
('BOTH', 'Both of HDFS and HIVE'),]

class TestForm(forms.Form):
    # hdfs_test = forms.MultipleChoiceField()
    # hive_test = forms.MultipleChoiceField()
    # hdfs_hive_test = forms.MultipleChoiceField()
    test_type = forms.MultipleChoiceField(required=True, widget=forms.RadioSelect(), choices=TEST_TYPE_CHOICES)
    event_textarea = forms.Textarea(attrs={'rows': '8', 'class': 'form-control', 'placeholder': 'Events...', 'id': 'event_textarea'})
    def __init__(self, *args, **kwargs):
        super(metaForm, self).__init__(*args, **kwargs)
        field.widget.attrs['test_type'] = 'your class name here'
from django import forms
TEST_TYPE_CHOICES = [
('HDFS', 'HDFS'),
('HIVE', 'HIVE'),
('BOTH', 'Both of HDFS and HIVE'),]

class TestForm(forms.Form):
    # hdfs_test = forms.MultipleChoiceField()
    # hive_test = forms.MultipleChoiceField()
    # hdfs_hive_test = forms.MultipleChoiceField()
    test_type = forms.MultipleChoiceField(required=True, widget=forms.RadioSelect(attrs={'class':'your class name here'}), choices=TEST_TYPE_CHOICES)
    event_textarea = forms.Textarea(attrs={'rows': '8', 'class': 'form-control', 'placeholder': 'Events...', 'id': 'event_textarea'})


Share : facebook icon twitter icon
Customizing django admin site - in row buttons

Customizing django admin site - in row buttons


By : Fima
Date : March 29 2020, 07:55 AM
this one helps. Suppose I have a model like this: , The list page is a form.
code :
<form id="changelist-form" action="" method="post">
def rename_action(modeladmin, request, queryset):
    queryset.update(name='Ni')
make_published.short_description = "Rename selected objects to 'Ni'"

class FooAdmin(admin.ModelAdmin):
    actions = [rename_action, ...]
class Foo(models.Model):
    ...

    def my_action_link(self, obj):
        return '<a href="/admin/app/foo/my_custom_action/%d/" class="link">Action name</a>' %obj.id
    my_action_link.short_description = 'My action'
    my_action_link.allow_tags = True
class FooAdmin(admin.ModelAdmin):
    ...

    list_display = ['name', 'my_action_link', ...]

    def get_urls(self):
        urls = super(FooAdmin, self).get_urls()
        my_urls = patterns('',
            (r'^my_custom_action/(?P<pk>\d+)/$', self.my_view)
        )
        return my_urls + urls

    @permission_required('foo.can_change')
    def my_view(self, request):
        obj = get_object_or_404(Foo, pk=pk)
        obj.do_something()
        # Redirect back to the change list. Or something else?
        # You could add some modelform to this view. :)
Customizing Radio buttons

Customizing Radio buttons


By : Dilip Chauhan
Date : March 29 2020, 07:55 AM
may help you . Realizing an idea sometimes is not really easy. If user just need to click/hover on the circle (of the radio button) to interact with it, we can easily customize the radio. But the normal behavior of a radio button is also allow user to click/hover on the label text to interact with it. That means we may need one more label (for the text). But it's not such easy. That label can only allow user to click to interact with the hidden radio, hovering on that label won't effect anything (normally that label is appended at last, so we also have no way to traverse backwards to select the fake radio (which are made by 2 pseudo-element :before and :after). So I decided to use only 1 label. This label contains an empty span element as the first child, following this span is of course the text for the radio button. The span element is where we style the fake radio. However if letting them inline by default and the text is long, it will jump to the next line and vertically line up with the left edge of the fake radio (which is right above at the first line) , this is considered to be very ugly and should be avoided. So we need to make the label displayed as a table (using display:table), the first column is the span element (apply display:table-cell), the label text will be automatically wrapped by the second column. That way when the text is long, all the lines will be wrapped by the second column.
Here are the code details:
code :
<div>
  <span class='radio'>
    <input type='radio' id='r1'name='radios' checked='true'/>
    <label for='r1'><span></span>
      Can I be wrapped when I grow longer and longer?
    </label>
  </span><br/>
  <span class='radio'>
    <input type='radio' id='r2' name='radios'/>
    <label for='r2'><span></span>Vote me up please :)</label>
  </span>
</div>
span.radio > input[type='radio'] {
  display:none;    
}
span.radio > label {    
  display:table;     
}
span.radio > label > span {
  display:table-cell;
  width:20px;    
  white-space:nowrap;    
}
span.radio > label > span:before {
  content:'';
  width:20px;
  height:20px;
  border-radius:50%;
  display:inline-block;
  box-shadow: 0 0 4px 2px gray inset;
  vertical-align:middle;       
}

span.radio > label > span:after {
  content:'';
  position:relative;    
  display:inline-block;
  vertical-align:middle; 
  left:-16px;    
  width:12px;
  height:12px;
  border-radius:50%;
  box-shadow:0 0 3px 1px red;
  background:radial-gradient(circle at 2px 2px, white, red);
  visibility:hidden;
}
span.radio > label:hover > span:before {
  box-shadow: 0 0 5px 3px orange inset;
}
span.radio > input[type='radio']:checked + label > span:after {
  visibility:visible;
}
span.radio {    
  display:inline-block;
  margin-bottom:3px;
}

/* This is not part of the custom radio input, it's just a group container 
to test the text wrapping ability of the label text */
div {
  border:1px solid black;
  width:400px;     
  font-size:30px;
  padding:5px;
}
Customizing Radio Buttons from Simple Form

Customizing Radio Buttons from Simple Form


By : Junaid Quadri
Date : March 29 2020, 07:55 AM
I hope this helps . I've never tried this. Let's take a look at css selectors: http://www.w3schools.com/css/css_attribute_selectors.asp
now, let's select all input type = "radio" and set the height and width:
code :
input[type="radio"] { //select all input type = "radio"
    height: 100px;  //change these to get correct size
    width: 100px;
}
Variable product attribute: Customizing each displayed radio buttons text value

Variable product attribute: Customizing each displayed radio buttons text value


By : belissimo
Date : March 29 2020, 07:55 AM
Does that help Here is your revisited code that will display only around the "Tab" attribute radio buttons custom displayed text a tag with a different class value based on a combination of the attribute slug and the $term_slug.
So you will be able to apply some CSS style colors to each radio button displayed custom text for the 'pa_tab' attribute only, adding those CSS rules to your active theme style.css…
code :
// Display the product variation price inside the variations dropdown.
add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name', 10, 1 );

function display_price_in_variation_option_name( $term ) {
    global $wpdb, $product;

    // Define HERE the targetted attribute taxonomy slug
    $tax_slug = 'pa_tab';

    // compatibility with WC +3
    $product_id = method_exists( $product, 'get_id' ) ? $product->get_id() : $product->id;

    if ( empty( $term ) || empty( $product_id ) )
        return $term;

    $result = $wpdb->get_var( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'" );

    $term_slug = ( ! empty( $result ) ) ? $result : $term;

    $variation_id = $wpdb->get_var( "
        SELECT postmeta.post_id AS product_id
        FROM {$wpdb->prefix}postmeta AS postmeta
        LEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id )
        WHERE postmeta.meta_key LIKE 'attribute_%'
        AND postmeta.meta_value = '$term_slug'
        AND products.post_parent = $product_id
    ");

    $parent = wp_get_post_parent_id( $variation_id );

    if ( $parent > 0 ) {

        $_product = wc_get_product( $variation_id );

        if ( has_term( $term, $tax_slug, $_product->id) )
            $output = ' <span class="'.$tax_slug.'-price">' . wp_kses( woocommerce_price( $_product->get_price() ), array() ) . '</span><span class="' . $tax_slug . '-' . $term_slug . '"> - ('.$term.')</span>';
        else
            $output = ' ' . $term;

        return $output;

    }
    return $term;

}
<td class="value">
    <div>
        <input type="radio" name="attribute_pa_color" value="option-blue" id="pa_tab_v_option-blue">
        <label for="pa_tab_v_option-blue"> 
            <span class="pa_tab-price">$99.00</span>
            <span class="pa_tab-option-blue"> - (Option Blue)</span>
        </label>
    </div>
    <div>
        <input type="radio" name="attribute_pa_color" value="option-green" id="pa_tab_v_option-green">
        <label for="pa_tab_v_option-green"> 
            <span class="pa_tab-price">$299.00</span>
            <span class="pa_tab-option-green"> - (Option Green)</span>
        </label>
    </div>
    <!-- ... / ... ... -->                      
</td>
span.pa_tab-price {
    font-family: lato, sans-serif; 
    font-size: medium;
}
span.pa_tab-option-blue, span.pa_tab-option-green,
span.pa_tab-option-purple, span.pa_tab-option-orange {
    font-family: lato, sans-serif; 
    font-size: medium;
    font-style: normal;
    font-weight: 300;
}
span.pa_tab-option-blue {
    color: blue;
}
span.pa_tab-option-green {
    color: green;
}
span.pa_tab-option-purple {
    color: purple;
}
span.pa_tab-option-orange {
    color: orange;
}
customizing checkboxes and radio buttons using CSS3

customizing checkboxes and radio buttons using CSS3


By : Jack Jax Caster
Date : March 29 2020, 07:55 AM
help you fix your problem Here i'm having checkboxes and radiobuttons with respective styles , Use this code:
Related Posts Related Posts :
  • How do I add a custom button next to a field in Django admin?
  • Bulk, partial updates with Django Rest Framework
  • Resize thumbnails django Heroku, 'backend doesn't support absolute paths'
  • How do you get pyapns (python push notification) working on a mac?
  • Django Haystack - How to force exact attribute match without stemming?
  • Django "with" template tag renders empty for ForeignKey relationship
  • override django admin change_list_results.html per model
  • Django sum a field based on foreign key
  • CommandError: The permission codename 'change_mymodel' clashes with a builtin permission for model 'myapp.MyModel'
  • How do I implement user registration with Django and AngularJS?
  • limit_choices_to in DjangoAdmin
  • how to integrate single sign on from disqus with django allauth
  • Django REST Framework nested relations without related names
  • Is eval Dangerous in Django
  • Django template location with Cloud9
  • django template looping through a list
  • Django deployment 500 server error, nothing in logs
  • Archiving model data in Django
  • Import app foreign key model class in another app model
  • string less or equal datetime django
  • Empty formset passing validation but not saving records
  • How to arrange fields of a form rendered by ModelForm?
  • Resolve Static URL on Server
  • heroku - DatabaseError: relation "south_migrationhistory" does not exist
  • 'QueryDict' object has no attribute 'GET'
  • Will a foreignkey link my two tables in this example?
  • How to restore related objects with django-reversion
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org