Code Monkey home page Code Monkey logo

Comments (3)

resujentoezequiel avatar resujentoezequiel commented on August 20, 2024 1

It's working.

I removed the
document.addEventListener('DOMContentLoaded', () => {
});

from bladewind.

mkocansey avatar mkocansey commented on August 20, 2024

@resujentoezequiel I just added a JS function to the helper.js file for this. Will be available in the next update but you can follow the steps below to have it working for you now.

  1. Add the function below to your project_root > public > vendor > bladewind > js > helpers.js
/**
 * Set the value of a datepicker
 * @return {void}
 * @param {string} el_name - name of the input field to update
 * @param {string} date - new value to set
 */
var setDatepickerValue = (el_name, date) => {
    let newValue = date;
    let input = domEl(`.${el_name}`);
    if (!input) {
        console.error(`No datepicker found with the name ${el_name}`);
        return;
    }
    if (!input._x_model) {
        console.error(`Alpine.js component not found for element ${el_name}`);
        return;
    }
    input._x_model.set(date);
}
  1. Define any datepicker but make sure to give it a name
<x-bladewind::datepicker name="invoice_date" />
  1. Set the value of the datepicker via Javascript
document.addEventListener('DOMContentLoaded', () => {
   setDatepickerValue('invoice_date', '2020-10-10');
});

The function expects the DOM content to have fully loaded to work. Ideally the DOM content should have fully loaded when you decide to call the function later on in your page but if you are testing with console.log, you will need to use the event listener as I have done in point 3.

Please let me know if this worked for you.

from bladewind.

mkocansey avatar mkocansey commented on August 20, 2024

Awesome

from bladewind.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.