2

Here my myVueInstance having two radio button and one text box. Based on click radio button options I should show / hide the text box.

<div id='myVueInstance'>

    <label>Show Text box or not ? </label>
    <input type="radio" id="one" value="true" v-model="picked">
        <label for="one">Yes</label>

        <input type="radio" id="two" value="false" v-model="picked" >
        <label for="two">No</label>
        <br>
        <span>Picked: {{ picked }}</span>
        <input  type='text' v-show='picked'> 

    </div>


<script type="text/javascript">
    var app = new Vue({
        el:'#myVueInstance',
        data:{

            title : 'My learning of Vue',
            picked:true
        }
     });
</script>

Note : I'm using Vue updated version.

1 Answer 1

2

Here, type of picked is becoming String when selecting radio button. Try this:

 <input  type='text' v-show="picked === 'true'">
...
...
...
 data:{
   title : 'My learning of Vue',
   picked: 'true'
 }

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you @Sajib Khan for your quick attention on this. I got the solution by adding v-show="picked === 'true'" on my text box. Great !.
And Sajib, If you are set picked: true instead of picked: 'true'. Then you no need to check that data types like v-show="picked === 'true'". Instead of that you can check like v-show="picked ==true". :)
=== is recommended, cause when we use == type conversion happens! :)
Yes so that I suggested as no need to pass as string type in el, as well as we no need to check ===. So if you are passed are string type in el, then we should check the type conversion also :) .
perfect, Helped me.

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.