Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Metronic Laravel Custom Javascript not working


hi Metronic Team

I am trying to add a product page to my Laravel project, but the JavaScript isn't functioning properly.

Code part :

1. add-product.blade.php

>

<button type="submit" id="kt_ecommerce_add_product_submit" class="btn btn-primary">
<span class="indicator-label">Save Changes</span>
<span class="indicator-progress">Please wait...
<span class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
</button>

@push("scripts")
<script type="text/javascript" src="{{ asset("assets/js/custom/apps/ecommerce/catalog/save-product.js") }}"></script>
@endpush


2. Inspect web page

>

<!--begin::Custom Javascript(optional)-->
<script src="http://127.0.0.1:8000/assets/js/custom/widgets.js"></script>
<script src="http://127.0.0.1:8000/assets/js/custom/apps/chat/chat.js"></script>
<script src="http://127.0.0.1:8000/assets/js/custom/utilities/modals/upgrade-plan.js"></script>
<script src="http://127.0.0.1:8000/assets/js/custom/utilities/modals/create-app.js"></script>
<script src="http://127.0.0.1:8000/assets/js/custom/utilities/modals/users-search.js"></script>
<script src="http://127.0.0.1:8000/assets/js/custom/utilities/modals/new-target.js"></script>
<!--end::Custom Javascript-->
<script type="text/javascript" src="http://127.0.0.1:8000/assets/js/custom/apps/ecommerce/catalog/save-product.js"></script>


Issue

>
When I click "Save Changes," it should trigger the handleSubmit function in save-product.js, but it is not working.

Could you please help me with making the JavaScript code work properly? I am having trouble with it and would appreciate your guidance. Thank you.
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (5)


Hello,

Thank you for reaching out. To better assist you, could you please check the console log for any JavaScript errors when you click "Save Changes"? This will help us identify if there are any issues with the execution of the JavaScript code.

You can open the browser's developer tools (usually by pressing F12 or right-clicking on the page and selecting "Inspect"), go to the "Console" tab, and look for any error messages.

Once you identify any errors, please share them with us.

Looking forward to resolving this issue for you.



Hi bro, I hope this reply can help clear things up.

This section of the code, has been thoroughly checked to ensure proper functionality.


add-product.blade.php
add-product.blade.php img link


When clicking the "Save Changes" button, the JavaScript code seems to be malfunctioning.


console inspect after "Save Changes" clicked
Console img link


What I was expecting was an HTML layout that something like this.


When you fail to fill in a required field, a modal error validator is triggered.
Expected result img link


"Please help me. Thank you."

Hi,

There are a couple of steps you can take to address the problem.

In your controller, make sure you include the 'formrepeater' vendor by using the addVendors method. This step is essential for loading the necessary JavaScript files for the form repeater plugin.

// Example in your controller
use App\Core\Layout\BaseController;

class YourController extends BaseController {
public function yourMethod() {
// Add "formrepeater" vendor
$this->addVendors(["formrepeater"]);

// Your other code...
}
}


If the above step did not work. Move to this step. In recent formrepeater update, it might be the path has been changed. Navigate to the /resources/mix/vendors/formrepeater/ directory and update the formrepeater.bundle.js file with the following code:

module.exports = [
"node_modules/jquery.repeater/src/lib.js",
"node_modules/jquery.repeater/src/jquery.input.js",
"node_modules/jquery.repeater/src/repeater.js",
];


After making these changes, run the following command to rebuild your assets:

npm run dev

This command will compile your assets with the updated configuration.
After completing these steps, check if the JavaScript for the form repeater plugin is now functioning as expected on your product page.

If you encounter any further issues or have additional details to share, feel free to let me know.



Hi Faizal, thank you so much for helping me out.
Everything is working perfectly now. Thanks again, brother!

I am using first solution without $this

// Example in your controller
use App\Core\Layout\BaseController;

class YourController extends BaseController {
public function yourMethod() {
// Add "formrepeater" vendor
addVendors(["formrepeater"]);

// Your other code...
}
}


I just have one more question, if you don't mind. Could you please help me with it?

I have created a form to submit a request to store data, I am using form.submit() but the description value is still null.

I know this description using quill, can you help me to fix the quill description to be included in the form request?

this is the screenshot :

1. try fill description form with quill.js


2. blade & quill.js file



3. form.submit()


4. request result description is null


Help me to fix description value to a form.submit is still null even though I have already fill the description value.



It seems that you are trying to use Quill.js and submit its contents in a form. However, using a div element as the editor container will not work, because div elements are not part of the form data. You need to use a hidden input element instead, and update its value with the editor’s innerHTML whenever the content changes. Here is an example of how you can do that:


<form method="post" >
<!-- Create the toolbar container -->
<div >
<button class="ql-bold">Bold</button>
<button class="ql-italic">Italic</button>
</div>

<!-- Create the editor container -->
<div >
<p>Hello World!</p>
</div>

<!-- Create a hidden input element -->
<input type="hidden" name="description" >

<input type="submit" value="Save">
</form>

<!-- Initialize Quill editor -->
<script>
var editor = new Quill("#editor", {
modules: {
toolbar: "#toolbar"
},
theme: "snow"
});

// Update the hidden input value whenever the editor changes
editor.on("text-change", function() {
var html = editor.root.innerHTML;
document.getElementById("hiddenInput").value = html;
});
</script>


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(