Search code examples
javascriptjquerycleave

How to set a default value to an <input/> element, formatted with Cleave.js?


I've tried to set default value by setting a value property:

new Cleave('.cleave-input-class-name', {
                time: true,
                timePattern: ['h', 'm']
            });
$(.cleave-input-class-name).value = '09:00';
Also I tried to do it without jQuery, it didn't work as well. How to set a default value to a Cleave-formatted input element?

Solution

  • You're mixing JS's native value assignment with jQuery, which won't work. Instead you'd use val(). You also need to inclose your selector in quotes (may have been intentional):

    $('.cleave-input-class-name').val('09:00');