Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VueJS 3 Ternary Operation on submitting a form

I was wondering this isn’t working

 <form @submit.prevent="isEditMode? handleEditRole : handleAddRole">

But when I tried

<form @submit.prevent="handleAddRole">

or handleEditRole, its working just fine.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m setting the isEditMode to false when the user click the Add Role but then they chose to edit a role then isEdmitMode will be true

>Solution :

Vue will not execute the function when it is returned from a ternary, you have to execute it yourself:

 <form @submit.prevent="isEditMode? handleEditRole($event) : handleAddRole($event)">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading