How to Call a Javascript function onclick event inside jinja template? - javascript

{% for person in teacher %}
<tr class="bg-gray-100 border-b">
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"></td>
<td class="p-0 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
<img src="{{person.customuser.profile_pic.url}}" class="rounded-lg w-32"
alt="Avatar" />
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<p>{{person.customuser.first_name}} {{person.customuser.last_name}}</p>
</td>
<td class="text-sm text-gray-900 font-light px-4 py-4 whitespace-nowrap">
{% for item in person.subjects.all %}
<p>{{item.name}}</p>
{% endfor %}
</td>
<td class="text-sm text-gray-900 font-light px-4 py-4 whitespace-nowrap">
<div class="flex items-center justify-center">
<div id="btnView" class="inline-flex shadow-md hover:shadow-lg focus:shadow-lg"
role="group">
<button type="button"
class="rounded-l inline-block px-6 py-2.5 bg-[#4951bf] text-white font-medium text-xs leading-tight uppercase hover:bg-blue-700 focus:bg-blue-700 focus:outline-none focus:ring-0 active:bg-blue-800 transition duration-150 ease-in-out">Edit</button>
<button onclick='viewDetails()'
type="button"
class=" inline-block px-6 py-2.5 bg-[#4951bf] text-white font-medium text-xs leading-tight uppercase hover:bg-green-700 focus:bg-green-700 focus:outline-none focus:ring-0 active:bg-green-800 transition duration-150 ease-in-out">View</button>
<button type="button"
class=" rounded-r inline-block px-6 py-2.5 bg-[#4951bf] text-white font-medium text-xs leading-tight uppercase hover:bg-red-700 focus:bg-red-700 focus:outline-none focus:ring-0 active:bg-blue-800 transition duration-150 ease-in-out">Delete</button>
</div>
</div>
</td>
</tr>
{% endfor %}
I want to call a javascript function viewDetails({{person.id}}) inside onclick event when the user presses the button.I want the value {{person.id}} to be passed as an argument which is coming from the for loop in jinja tag. Is it possible?

You can set value as onclick="viewDetails({{person.id}})"
<button onclick="viewDetails({{person.id}})" type="button"
class=" inline-block px-6 py-2.5 bg-[#4951bf] text-white font-medium text-xs leading-tight uppercase hover:bg-green-700 focus:bg-green-700 focus:outline-none focus:ring-0 active:bg-green-800 transition duration-150 ease-in-out">View</button>
Then in your javascript code do whatever you wants.
function viewDetails(personId) {
console.log(personId)
//do whatever you want to do with that `personId`
}

Related

How do I fix this CSS issue that arose when I changed to importing my vue layout globally?

I recently changed to importing the layout page of a project globally rather than doing so on each page that uses the layout. I understand that this change makes the layout component a parent of the pages using it (importing the layout component in each page makes it a child of the page), but I have now come to know that this also affects the CSS cascading and specificity rules.
I did some fiddling and managed to get things back to how it was but I'm still unable to fix the CSS of my nav section.
These are screenshots of what I have now:
I copied over the rendered HTML of the page to Tailwind Play and it generates the page as I expect, meaning what I have should work. This is the screenshot for that:
This is the rendered HTML code for this page:
<div class="min-h-screen dark:text-white bg-gray-100 dark:bg-gray-700 border-b border-gray-200"><nav><!-- Primary Navigation Menu --><div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"><div class="flex justify-between"><!-- Logo --><div class="pt-2"><img src="/img/Android-icon.png" alt="SmartWealth Logo" class="block h-9 w-auto"></div><!-- Navigation Links --><div class="hidden space-x-8 sm:-my-px sm:ml-10 sm:flex"><a class="inline-flex items-center px-1 pt-1 border-b-2 border-indigo-400 dark:border-indigo-800 text-sm font-medium leading-5 text-gray-700 dark:text-white focus:outline-none focus:border-indigo-700 dark:focus:border-indigo-200 transition" href="http://127.0.0.1:8000/dashboard"> Dashboard </a><a class="inline-flex items-center px-1 pt-1 border-b-2 border-transparent dark:border-transparent text-sm font-medium leading-5 text-gray-500 dark:text-white dark:hover:text-gray-300 hover:text-gray-800 dark:hover:border-gray-400 hover:border-gray-300 focus:outline-none focus:text-gray-700 dark:focus:text-gray-200 focus:border-gray-300 dark:focus:border-gray-100 transition" href="http://127.0.0.1:8000/users"> Users </a></div><!-- Dropdown Navigation Menu --><div class="hidden sm:flex sm:items-center sm:ml-6"><!-- Settings Dropdown --><div class="ml-3"><div class="relative"><div><button class="flex text-sm border-2 border-transparent rounded-full focus:outline-none focus:border-gray-300 transition"><img class="h-8 w-8 rounded-full object-cover" src="https://smartwealth.s3.us-west-004.backblazeb2.com/profile-photos/x6ykUSsxOgm220vMTZbvaIIGe5Nu3wEsg9c0g469.jpg" alt="Adefowowe Adebamowo"></button></div><!-- Full Screen Dropdown Overlay --><div class="fixed inset-0 z-40" style="display: none;"></div><div class="absolute z-50 mt-2 rounded-md shadow-lg w-48 origin-top-left left-0" style="display: none;"><div class="rounded-md ring-1 ring-black ring-opacity-5 py-1 bg-white"><!-- Account Management --><div class="px-4 py-2 text-xs text-gray-400"> Manage Account </div><!--v-if--><div><a class="block px-4 py-2 text-sm leading-5 text-gray-700 dark:hover:bg-gray-500 hover:bg-gray-200 focus:outline-none dark:focus:bg-gray-500 focus:bg-gray-200 transition" href="http://127.0.0.1:8000/manage/rbac"> Manage Roles and Permissons </a></div><div><a class="block px-4 py-2 text-sm leading-5 text-gray-700 dark:hover:bg-gray-500 hover:bg-gray-200 focus:outline-none dark:focus:bg-gray-500 focus:bg-gray-200 transition" href="http://127.0.0.1:8000/user/profile"> Account Profile </a></div><div><a class="block px-4 py-2 text-sm leading-5 text-gray-700 dark:hover:bg-gray-500 hover:bg-gray-200 focus:outline-none dark:focus:bg-gray-500 focus:bg-gray-200 transition" href="http://127.0.0.1:8000/investment-profile/create"> Risk Assessment </a></div><!--v-if--><!--v-if--><!--v-if--><div><a class="block px-4 py-2 text-sm leading-5 text-gray-700 dark:hover:bg-gray-500 hover:bg-gray-200 focus:outline-none dark:focus:bg-gray-500 focus:bg-gray-200 transition" href="http://127.0.0.1:8000/providers/authorisation"> Provider Authorisation </a></div><div><a class="block px-4 py-2 text-sm leading-5 text-gray-700 dark:hover:bg-gray-500 hover:bg-gray-200 focus:outline-none dark:focus:bg-gray-500 focus:bg-gray-200 transition" href="http://127.0.0.1:8000/chat/messages"> Chats </a></div><!--v-if--><div><a class="block px-4 py-2 text-sm leading-5 text-gray-700 dark:hover:bg-gray-500 hover:bg-gray-200 focus:outline-none dark:focus:bg-gray-500 focus:bg-gray-200 transition" href="http://127.0.0.1:8000/user/api-tokens"> API Tokens </a></div><!-- Authentication --><form><div><button type="submit" class="block w-full px-4 py-2 text-sm leading-5 text-gray-700 text-left dark:hover:bg-gray-500 hover:bg-gray-200 focus:outline-none dark:focus:bg-gray-500 focus:bg-gray-200 transition"> Log Out </button></div></form></div></div></div></div><!--Notifications Dropdown --><div class="mx-2"><div class="relative"><div><div><span class=""><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-4 h-4"><path fill-rule="evenodd" d="M5.25 9a6.75 6.75 0 0113.5 0v.75c0 2.123.8 4.057 2.118 5.52a.75.75 0 01-.297 1.206c-1.544.57-3.16.99-4.831 1.243a3.75 3.75 0 11-7.48 0 24.585 24.585 0 01-4.831-1.244.75.75 0 01-.298-1.205A8.217 8.217 0 005.25 9.75V9zm4.502 8.9a2.25 2.25 0 104.496 0 25.057 25.057 0 01-4.496 0z" clip-rule="evenodd"></path></svg></span></div></div><!-- Full Screen Dropdown Overlay --><div class="fixed inset-0 z-40" style="display: none;"></div><div class="absolute z-50 mt-2 rounded-md shadow-lg w-48 origin-top-left left-0" style="display: none;"><div class="rounded-md ring-1 ring-black ring-opacity-5 py-1 bg-white"><!-- Notifications Management --><div class="block px-4 py-2 text-xs text-gray-400"> Your Notifications </div><div class="block px-4 py-2 text-xs text-gray-400"><button class="mx-2">x</button><button>Mark all as read</button></div><div class="bg-white"></div></div></div></div></div><!-- Page Theme Toggle --><div class="ml-2 flex items-right"><button><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-4 h-4"><path fill-rule="evenodd" d="M9.528 1.718a.75.75 0 01.162.819A8.97 8.97 0 009 6a9 9 0 009 9 8.97 8.97 0 003.463-.69.75.75 0 01.981.98 10.503 10.503 0 01-9.694 6.46c-5.799 0-10.5-4.701-10.5-10.5 0-4.368 2.667-8.112 6.46-9.694a.75.75 0 01.818.162z" clip-rule="evenodd"></path></svg></button></div></div></div><!-- Hamburger --><div class="-mr-2 flex items-center sm:hidden"><button class="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:bg-gray-100 focus:text-gray-500 transition"><svg class="h-6 w-6" stroke="currentColor" fill="none" viewBox="0 0 24 24"><path class="inline-flex" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path><path class="hidden" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg></button></div><!-- Responsive Navigation Menu --><div class="hidden sm:hidden"><div class="pt-2 pb-3 space-y-1"><div><a class="block pl-3 pr-4 py-2 border-l-4 border-indigo-400 dark:border-indigo-800 text-base font-medium dark:font-bold text-indigo-700 dark:text-indigo-800 bg-indigo-50 dark:bg-gray-800 focus:outline-none focus:text-indigo-800 dark:focus:text-indigo-800 focus:bg-indigo-800 dark:focus:bg-gray-800 focus:border-indigo-700 dark:focus:border-indigo-200 transition" href="http://127.0.0.1:8000/dashboard"> Dashboard </a></div><div><a class="block pl-3 pr-4 py-2 border-l-4 border-transparent dark:border-transparent text-base font-medium text-gray-600 dark:text-gray-300 dark:hover:text-gray-300 hover:text-gray-800 dark:hover:bg-gray-25 hover:bg-gray-50 hover:border-gray-300 dark:hover:border-gray-200 focus:outline-none focus:text-gray-800 dark:focus:text-gray-200 focus:bg-gray-50 dark:focus:bg-gray-25 focus:border-gray-300 dark:focus:border-gray-100 transition" href="http://127.0.0.1:8000/users"> Users </a></div></div><!-- Responsive Settings Options --><div class="pt-4 pb-1 border-t border-gray-200"><div class="flex items-center px-4"><div class="flex-shrink-0 mr-3"><img class="h-10 w-10 rounded-full object-cover" src="https://smartwealth.s3.us-west-004.backblazeb2.com/profile-photos/x6ykUSsxOgm220vMTZbvaIIGe5Nu3wEsg9c0g469.jpg" alt="Adefowowe Adebamowo"></div><div class="ml-2"><div class="relative"><div><div><span class=""><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-4 h-4"><path fill-rule="evenodd" d="M5.25 9a6.75 6.75 0 0113.5 0v.75c0 2.123.8 4.057 2.118 5.52a.75.75 0 01-.297 1.206c-1.544.57-3.16.99-4.831 1.243a3.75 3.75 0 11-7.48 0 24.585 24.585 0 01-4.831-1.244.75.75 0 01-.298-1.205A8.217 8.217 0 005.25 9.75V9zm4.502 8.9a2.25 2.25 0 104.496 0 25.057 25.057 0 01-4.496 0z" clip-rule="evenodd"></path></svg></span></div></div><!-- Full Screen Dropdown Overlay --><div class="fixed inset-0 z-40" style="display: none;"></div><div class="absolute z-50 mt-2 rounded-md shadow-lg w-48 origin-top-left left-0" style="display: none;"><div class="rounded-md ring-1 ring-black ring-opacity-5 py-1 bg-white"><!-- Notifications Management --><div class="block px-4 py-2 bg-white text-xs text-gray-400"> Your Notifications </div><div class="block px-4 py-2 bg-white text-xs text-gray-400"><button class="mx-2">x</button><button>Mark all as read</button></div><div class="bg-white dark:bg-gray-800"></div></div></div></div></div><div class="ml-2"><button><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-4 h-4"><path fill-rule="evenodd" d="M9.528 1.718a.75.75 0 01.162.819A8.97 8.97 0 009 6a9 9 0 009 9 8.97 8.97 0 003.463-.69.75.75 0 01.981.98 10.503 10.503 0 01-9.694 6.46c-5.799 0-10.5-4.701-10.5-10.5 0-4.368 2.667-8.112 6.46-9.694a.75.75 0 01.818.162z" clip-rule="evenodd"></path></svg></button></div></div><div class="mt-3 space-y-1"><!--v-if--><div><a class="block pl-3 pr-4 py-2 border-l-4 border-transparent dark:border-transparent text-base font-medium text-gray-600 dark:text-gray-300 dark:hover:text-gray-300 hover:text-gray-800 dark:hover:bg-gray-25 hover:bg-gray-50 hover:border-gray-300 dark:hover:border-gray-200 focus:outline-none focus:text-gray-800 dark:focus:text-gray-200 focus:bg-gray-50 dark:focus:bg-gray-25 focus:border-gray-300 dark:focus:border-gray-100 transition" href="http://127.0.0.1:8000/manage/rbac"> Manage Roles and Permissons </a></div><div><a class="block pl-3 pr-4 py-2 border-l-4 border-transparent dark:border-transparent text-base font-medium text-gray-600 dark:text-gray-300 dark:hover:text-gray-300 hover:text-gray-800 dark:hover:bg-gray-25 hover:bg-gray-50 hover:border-gray-300 dark:hover:border-gray-200 focus:outline-none focus:text-gray-800 dark:focus:text-gray-200 focus:bg-gray-50 dark:focus:bg-gray-25 focus:border-gray-300 dark:focus:border-gray-100 transition" href="http://127.0.0.1:8000/user/profile"> Account Profile </a></div><div><a class="block pl-3 pr-4 py-2 border-l-4 border-transparent dark:border-transparent text-base font-medium text-gray-600 dark:text-gray-300 dark:hover:text-gray-300 hover:text-gray-800 dark:hover:bg-gray-25 hover:bg-gray-50 hover:border-gray-300 dark:hover:border-gray-200 focus:outline-none focus:text-gray-800 dark:focus:text-gray-200 focus:bg-gray-50 dark:focus:bg-gray-25 focus:border-gray-300 dark:focus:border-gray-100 transition" href="http://127.0.0.1:8000/investment-profile/create"> Risk Assessment </a></div><!--v-if--><!--v-if--><!--v-if--><div><a class="block pl-3 pr-4 py-2 border-l-4 border-transparent dark:border-transparent text-base font-medium text-gray-600 dark:text-gray-300 dark:hover:text-gray-300 hover:text-gray-800 dark:hover:bg-gray-25 hover:bg-gray-50 hover:border-gray-300 dark:hover:border-gray-200 focus:outline-none focus:text-gray-800 dark:focus:text-gray-200 focus:bg-gray-50 dark:focus:bg-gray-25 focus:border-gray-300 dark:focus:border-gray-100 transition" href="http://127.0.0.1:8000/providers/authorisation"> Provider Authorisation </a></div><div><a class="block pl-3 pr-4 py-2 border-l-4 border-transparent dark:border-transparent text-base font-medium text-gray-600 dark:text-gray-300 dark:hover:text-gray-300 hover:text-gray-800 dark:hover:bg-gray-25 hover:bg-gray-50 hover:border-gray-300 dark:hover:border-gray-200 focus:outline-none focus:text-gray-800 dark:focus:text-gray-200 focus:bg-gray-50 dark:focus:bg-gray-25 focus:border-gray-300 dark:focus:border-gray-100 transition" href="http://127.0.0.1:8000/chat/messages"> Chats </a></div><!--v-if--><div><a class="block pl-3 pr-4 py-2 border-l-4 border-transparent dark:border-transparent text-base font-medium text-gray-600 dark:text-gray-300 dark:hover:text-gray-300 hover:text-gray-800 dark:hover:bg-gray-25 hover:bg-gray-50 hover:border-gray-300 dark:hover:border-gray-200 focus:outline-none focus:text-gray-800 dark:focus:text-gray-200 focus:bg-gray-50 dark:focus:bg-gray-25 focus:border-gray-300 dark:focus:border-gray-100 transition" href="http://127.0.0.1:8000/user/api-tokens"> API Tokens </a></div><!-- Authentication --><form method="POST"><div><button class="block pl-3 pr-4 py-2 border-l-4 border-transparent dark:border-transparent text-base font-medium text-gray-600 dark:text-gray-300 dark:hover:text-gray-300 hover:text-gray-800 dark:hover:bg-gray-25 hover:bg-gray-50 hover:border-gray-300 dark:hover:border-gray-200 focus:outline-none focus:text-gray-800 dark:focus:text-gray-200 focus:bg-gray-50 dark:focus:bg-gray-25 focus:border-gray-300 dark:focus:border-gray-100 transition w-full text-left"> Log Out </button></div></form></div></div></div></div></nav><!-- Display messages from backend sent as flash page props --><div><!--v-if--></div><!-- Display notifications broadcasts (wrap into a reusable component) --><!--v-if--><!-- Page Heading --><!--v-if--><!-- Page Content --><main><!----><div slot="header" class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8"><h2 class="font-semibold text-xl text-gray-800 dark:text-gray-100 leading-tight"> Dashboard </h2></div><div class="py-8"><div class="max-w-3xl mx-auto sm:px-6 lg:px-8"><div class="rounded"><div class="p-6 sm:px-20 border border-gray-200 rounded"><div class="text-2xl"> Hello Adefowowe, welcome to SmartWealth! </div><div class="mt-1 text-sm"><p> Now that you're here, the first step is to take a risk assessment test to gauge your investment capacity and risk disposition. You can do that here: <a class="inline-flex items-center px-1 pt-1 border-b-2 border-transparent dark:border-transparent text-sm font-medium leading-5 text-gray-500 dark:text-white dark:hover:text-gray-300 hover:text-gray-800 dark:hover:border-gray-400 hover:border-gray-300 focus:outline-none focus:text-gray-700 dark:focus:text-gray-200 focus:border-gray-300 dark:focus:border-gray-100 transition" href="http://127.0.0.1:8000/investment-profile/create"><strong> Risk Assessment </strong></a></p></div></div></div></div></div></main></div>
What can I do to get things working properly?
you have to append #media screen sizes in your CSS file as:
/* Small */
#media (min-width: 768px) {
.container {
width: 750px;
}
}
/* Medium */
#media (min-width: 992px) {
.container {
width: 970px;
}
}
/* Large */
#media (min-width: 1200px) {
.container {
width: 1170px;
}
}
<div class="head">
<div class="container">
<p>some text</p>
</div>
</div>

How to get dropdown button to work in react

How do I get the drop-down button to work within a card in React?
I am building in react and using Tailwind css card to display API information. I do not want to show all the info at once so plan to use a dropdown to say "show more" but somehow it won't work.
Button shows but when clicked nothing happens. Here is the code below, this also applies to dropdown code from the tailwind official website so something wrong with my app that I cannot figure out.
You can see the code display here
Thank you
<h5 class="text-gray-900 text-xl leading-tight font-medium mb-2">Card title</h5>
<p class="text-gray-700 text-base mb-4">
Some quick example text to build on the card title and make up the bulk of the card's
content.
</p>
<button
class="dropdown-toggle inline-block px-6 py-2.5 bg-purple-600 text-white font-medium text-xs leading-tight uppercase rounded shadow-md hover:bg-purple-700 hover:shadow-lg focus:bg-purple-700 focus:shadow-lg focus:outline-none focus:ring-0 active:bg-purple-800 active:shadow-lg active:text-white transition duration-150 ease-in-out flex items-center whitespace-nowrap"
type="button"
id="dropdownMenuButton2"
data-bs-toggle="dropdown"
aria-expanded="false"
>
SHOW MORE
<svg
aria-hidden="true"
focusable="false"
data-prefix="fas"
data-icon="caret-down"
class="w-2 ml-2"
role="img"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 320 512"
>
<path
fill="currentColor"
d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z"
></path>
</svg>
</button>
<ul
class="dropdown-menu min-w-max absolute hidden bg-white text-base z-50 float-left py-2 list-none text-left rounded-lg shadow-lg mt-1 hidden m-0 bg-clip-padding border-none bg-gray-800"
aria-labelledby="dropdownMenuButton2"
>
<h6
class="text-gray-400 font-semibold text-sm py-2 px-4 block w-full whitespace-nowrap bg-transparent"
>
Dropdown header
</h6>
<span
class="text-sm py-2 px-4 font-normal block w-full whitespace-nowrap bg-transparent text-gray-300"
>Dropdown item text</span
>
<li>
<a
class="dropdown-item text-sm py-2 px-4 font-normal block w-full whitespace-nowrap bg-transparent text-gray-300 hover:bg-gray-700 hover:text-white focus:text-white focus:bg-gray-700 active:bg-blue-600"
href="#"
>Action</a
>
</li>
<li>
<a
class="dropdown-item text-sm py-2 px-4 font-normal block w-full whitespace-nowrap bg-transparent text-gray-300 hover:bg-gray-700 hover:text-white focus:text-white focus:bg-gray-700"
href="#"
>Another action</a
>
</li>
<li>
<a
class="dropdown-item text-sm py-2 px-4 font-normal block w-full whitespace-nowrap bg-transparent text-gray-300 hover:bg-gray-700 hover:text-white focus:text-white focus:bg-gray-700"
href="#"
>Something else here</a
>
</li>
<li><hr class="h-0 my-2 border border-solid border-t-0 border-gray-300 opacity-25" /></li>
<li>
<a
class="dropdown-item text-sm py-2 px-4 font-normal block w-full whitespace-nowrap bg-transparent text-gray-300 hover:bg-gray-700 hover:text-white focus:text-white focus:bg-gray-700"
href="#"
>Separated link</a
>
</li>
</ul>
</div>
</div>
Just remove hidden class from ul tag and you can use one of component library like flowbite or daisyui

Capture value of input counter created with tailwind and alpine JS

I have a counter made with Tailwind and Alpine JS. I am trying to capture the value of the input field when the user types in or uses the counter buttons, but I am only able to capture the value when a user types their response. Any ideas on how to capture the values when the user uses the counter buttons to increment or decrement?
<!-- counter -->
<div class="z-50 relative" x-data="{ quantity : 0 }">
<div class="fisker-bold text-gray-900 text-center mx-auto text-sm">
Quantity</div>
<div class=" mt-1 mb-3 flex rounded-md justify-center">
<button #click="quantity--" type="button"
class=" relative inline-flex items-center space-x-2 px-4 py-2 text-sm font-medium rounded-l-md text-gray-700 bg-gray-50 hover:bg-gray-100 focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 bg-gray-300">
-
</button>
<div class="relative flex items-stretch focus-within:z-10">
<input type="text" x-model="quantity" name="qty-1" id="qty-1"
class="text-center focus:ring-blue-500 focus:border-indigo-500 block w-20 text-gray-900 rounded-none pl-3 sm:text-sm border-gray-300 bg-gray-300"
value="0">
</div>
<button #click="quantity++" type="button"
class="relative inline-flex items-center space-x-2 px-4 py-2 text-sm font-medium rounded-r-md text-gray-700 bg-gray-50 hover:bg-gray-100 focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 bg-gray-300">
+
</button>
</div>
</div>
<!-- counter -->
<script>
$(function () {
$("#qty-1").on("change", function () {
var text = $(this).find('option:selected').text();
$('#qty').text(' x' + text);
});
});
</script>

How to get html element in #document of iframe tag

i'm new with Stack Overflow. I don't have enough 10 reputation to embed image. Sorry for this inconvenience but I have some question about iframe tag:
I tried some way to get html element in #document of iframe tag, but somehow it still not work. Can you explain why for me and how can I get element have id = "check". I'm try to learn
There is test.blade.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<title>Document</title>
</head>
<body>
<iframe src="/login" width="100%" height="100%" id="iframe"></iframe>
<script>
const iframe = $("#iframe");
console.log(iframe);
console.log(iframe.contents());
console.log(iframe.contents().find("#check").html());
</script>
</body>
</html>
There is login.blade.php
<x-common :title="'Login'">
<x-slot name='main'>
<div class="w-full lg:w-4/12 px-4">
<div class="pt-20"></div>
<div
class="relative flex flex-col min-w-0 break-words w-full mb-6 shadow-lg rounded-lg bg-gray-200 border-0">
<div class="rounded-t mb-0 px-6 py-6">
<div class="text-center mb-3">
<h6 class="text-gray-500 text-sm font-bold">
Sign in with
</h6>
</div>
<div class="btn-wrapper text-center">
<button
class="bg-white active:bg-gray-50 text-gray-700 px-4 py-2 rounded outline-none focus:outline-none mr-2 mb-1 uppercase shadow hover:shadow-md inline-flex items-center font-bold text-xs ease-linear transition-all duration-150"
type="button">
<img alt="..." class="w-5 mr-1"
src="{{ asset('assets/img/github.svg') }}" />Github</button><button
class="bg-white active:bg-gray-50 text-gray-700 px-4 py-2 rounded outline-none focus:outline-none mr-1 mb-1 uppercase shadow hover:shadow-md inline-flex items-center font-bold text-xs ease-linear transition-all duration-150"
type="button">
<img alt="..." class="w-5 mr-1" src="{{ asset('assets/img/google.svg') }}" />Google
</button>
</div>
<hr class="mt-6 border-b-1 border-gray-300" />
</div>
<div class="flex-auto px-4 lg:px-10 py-10 pt-0">
<div class="text-gray-400 text-center mb-3 font-bold">
<small>Or sign in with credentials</small>
</div>
<x-alert></x-alert>
<form action="login" method="post">
<div class="relative w-full mb-3">
<label class="block uppercase text-gray-600 text-xs font-bold mb-2"
for="grid-password">Email</label><input type="email"
class="border-0 px-3 py-3 placeholder-gray-300 text-gray-600 bg-white rounded text-sm shadow focus:outline-none focus:ring w-full ease-linear transition-all duration-150"
placeholder="Email" name="email" value="{{ old('email') }}" />
</div>
<div class="relative w-full mb-3">
<label class="block uppercase text-gray-600 text-xs font-bold mb-2"
for="grid-password">Password</label><input type="password" autocomplete="on"
class="border-0 px-3 py-3 placeholder-gray-300 text-gray-600 bg-white rounded text-sm shadow focus:outline-none focus:ring w-full ease-linear transition-all duration-150"
placeholder="Password" name="password" value="{{ old('password') }}" />
</div>
<div id="check">
<label class="inline-flex items-center cursor-pointer"><input id="customCheckLogin"
type="checkbox"
class="form-checkbox border-0 rounded text-gray-700 ml-1 w-5 h-5 ease-linear transition-all duration-150"
name="remember" /><span class="ml-2 text-sm font-semibold text-gray-600">Remember
me</span></label>
</div>
<div class="text-center mt-6">
<button
class="bg-gray-800 text-white active:bg-gray-600 text-sm font-bold uppercase px-6 py-3 rounded shadow hover:shadow-lg outline-none focus:outline-none mr-1 mb-1 w-full ease-linear transition-all duration-150"
type="submit">
Sign In
</button>
</div>
#csrf
</form>
<div class="flex flex-wrap">
<div class="w-1/2">
<a href="password/forgot" class="text-gray-500 text-sm font-bold"><small>Forgot
password?</small></a>
</div>
<div class="w-1/2 text-right">
<a href="register" class="text-gray-500 text-sm font-bold"><small>Create new
account</small></a>
</div>
</div>
</div>
</div>
</div>
</x-slot>
</x-common>
Console
Elements
I think the iframe document is not ready when you try to access the nodes. You should wait for the iframe load event after that you can access the child nodes.
$('#iframe').on("load", function() {
// do the stuff here
});
You should try to catch the event 'load' of the iframe using javascript:
document.querySelector("iframe").addEventListener( "load", function() {
console.log("This will appear on the console when the iframe is loaded");
});
Or you can use jquery instead:
$('iframe').on("load", function() {
// content for the iframe when it is loaded
}

Need to pass a input value to another DIV in AlpineJS

I need to pass the input values to a modal, but i can't do it with x-ref. Is this the right way to do it?
<div x-data="orderSearch()" class="container mt-2 mx-auto" x-ref="root">
<div class="grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-2 mt-2 mb-3">
<div class="card m-1 p-1 cursor-pointer border border-gray-400 rounded-lg hover:shadow-md hover:border-opacity-0 transform hover:-translate-y-1 transition-all duration-200 bg-green-200">
<div class="flex flex-row w-full py-2 px-2 m-1 text-sm text-green-800" x-data="{ qty: '', val: '', total: ''}" x-effect="total = qty * val">
Definir estratégia de COMPRA:
<input class="field shadow appearance-none border rounded w-1/3 py-2 px-2 my-1 mx-1 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="valorcompra" type="text" placeholder="Valor" autofocus x-model.number="qty" x-ref="valorcompra" #keydown.enter="fetchOrder('buy',$refs.quantidadecompra.value,$refs.valorcompra.value)">
<input class="field shadow appearance-none border rounded w-1/3 py-2 px-2 my-1 mx-1 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="quantidadecompra" type="text" placeholder="Quantidade" x-model.number="val" x-ref="quantidadecompra" #keydown.enter="fetchOrder('buy',$refs.quantidadecompra.value,$refs.valorcompra.value)">
<input class="field shadow appearance-none border rounded w-1/3 py-2 px-2 my-1 mx-1 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="totalcompra" type="text" placeholder="Total" x-model.number="total" x-ref="totalcompra" #keydown.enter="fetchOrder('buy',$refs.quantidadevenda.value,$refs.valorcompra.value)" x-bind:disabled="true">
</div>
</div>
<div class="card m-1 p-1 cursor-pointer border border-gray-400 rounded-lg hover:shadow-md hover:border-opacity-0 transform hover:-translate-y-1 transition-all duration-200 bg-red-200">
<div class="flex flex-row w-full py-2 px-2 m-1 text-sm text-red-800" x-data="{ qty: '', val: '', total: ''}" x-effect="total = qty * val">
Definir estratégia de VENDA:
<input class="field shadow appearance-none border rounded w-1/3 py-2 px-2 my-1 mx-1 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="valorvenda" type="text" placeholder="Valor" autofocus x-model.number="qty" x-ref="valorvenda" #keydown.enter="fetchOrder('sell',$refs.quantidadevenda.value,$refs.valorvenda.value)">
<input class="field shadow appearance-none border rounded w-1/3 py-2 px-2 my-1 mx-1 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="quantidadevenda" type="text" placeholder="Quantidade" x-model.number="val" x-ref="quantidadevenda" #keydown.enter="modal=true">
<input class="field shadow appearance-none border rounded w-1/3 py-2 px-2 my-1 mx-1 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" id="totalvenda" type="text" placeholder="Total" x-model.number="total" x-ref="totalvenda" #keydown.enter="fetchOrder('sell',$refs.quantidadevenda.value,$refs.valorvenda.value)" x-bind:disabled="true">
</div>
</div>
</div>
<!-- Dialog (full screen) -->
<div class="absolute top-0 left-0 flex items-center justify-center w-full h-full" style="background-color: rgba(0,0,0,.5);" x-show="modal">
<!-- A basic modal dialog with title, body and one button to close -->
<div class="h-auto p-4 mx-2 text-left bg-white rounded shadow-xl md:max-w-xl md:p-6 lg:p-8 md:mx-0">
<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
<h3 class="text-lg font-medium leading-6 text-gray-900">
Confirmação!
</h3>
<div class="mt-2">
<p class="text-sm leading-5 text-gray-500" x-text="'Deseja cadastrar a ordem de venda?'">
</p>
</div>
</div>
<!-- One big close button. --->
<div class="mt-4 flex justify-between">
<div class="cancela px-4 bg-red-400 p-3 rounded-lg text-white hover:bg-red-600" #click="modal=false">Cancelar</div>
<div class="ok px-4 bg-green-400 p-3 rounded-lg text-white hover:bg-green-600" #click="fetchOrder('sell',$refs.quantidadevenda.value,$refs.valorvenda.value)">Confirmar</div>
</div>
</div>
</div>
<!-- fim modal div -->
</div>
Must be read input values here:
<div class="ok px-4 bg-green-400 p-3 rounded-lg text-white hover:bg-green-600" #click="fetchOrder('sell',$refs.quantidadevenda.value,$refs.valorvenda.value)">Confirmar</div>
I tried to find this answer for two days but i cant.
Can you help me?
i tried a $store solution and it1s done:
<script>
const element = document.querySelector("#valorvenda")
element.addEventListener('change', (event) => {
const quantidadevenda = document.querySelector("#quantidadevenda").value
Alpine.store('venda', {
valorcompra: document.querySelector("#valorcompra").value,
quantidadecompra:quantidadevenda,
valorvenda: event.target.value,
quantidadevenda: quantidadevenda,
})
console.log(Alpine.store('fields').valorvenda);
})
</script>
It's like a state management and works fine!
Thanks all.

Categories

Resources