0

enter image description here

see the image plx

there are some readonly field that i set up on django, but i want to read the values using Jquery but really idk how to do it, i want to do it cuz depending of the value that is set on field "tipo" i want a make some values visibles or not.

let tipo_persona_check = function(){
    if ($('#id_tipo').val() == 'fisica'){
        $('.field-empresa').hide();
        $('label[for=id_persona').text('Suscriptor');
    }else{
        $('label[for=id_persona').text('Apoderado');
        $('.field-empresa').show();
    }

in this case im hidding or showing field empresa depending of the value of id_tipo, but when it is on readonly, this id not exist, there is just a span class called readonly (for all readonly) with the value, but idk how to get from it, i need to know if the value is "fisica" or another from the readonly field tipo, to do things.

any ideas?

1 Answer 1

0

I did not check whether the ID is really visible when this is the case We assume that the ID is not seen.

The solution is that you can add an input in that section so that you can find the ID from it.

admin.py

@admin.register(SomeModel)
class SomeModelAdmin(admin.ModelAdmin):
    def id_field(self, obj):
        return mark_safe(f"<input type='hidden' id='ID' value='{obj.pk}'>")
    readonly_fields = ["id_field"]

and in you js file:

id = document.getElementById('ID').value
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.