$('#add_newsletter').on("click", function (e) {
// alert('jh');
    // $.validator.addMethod("quillNotEmpty", function(value, element) {
    //     var quill = new Quill('#news-quill-add');
    //     return quill.getText().trim().length > 0;
    // }, "Please enter description ");
    
    $('#add_blog_form').validate({
        // ignore: [],
        // debug: false,
        rules: {
            article_name: {
                required: true
            },
            article_dis: {
                required: true,
                quillNotEmpty: true
            },
            article_image: {
                required: true
            },
            article_thmb: {
                required: true
            },
            category: {
                required: true
            },
        },
        messages: {
            article_name: {
                required: "Please Enter Article name"
            },
            article_dis: {
                required: "Please Enter Description"
            },
            article_image: {
                required: "Please Select Image"
            },
            category: {
                required: "Please Select Article Category"
            },
        },
        errorClass: 'error-message',
        submitHandler: function (form) {
            
            var quillContent = quill.root.innerHTML;
            $('#article_des').val(quillContent);base_url = url_path;
            var formData = new FormData(form);
            $('#add_newsletter').text('Please wait...').attr('disabled', true);
            
            $.ajaxSetup({
                headers: {
                    "X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
                },
            });

            $.ajax({
                url: base_url + '/manage_insert_news',
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function (response) {
                    if (response.status == 200) {
                        toastr.success('News and Article Added Successfully');
                        setTimeout(function () {
                            window.location.href = base_url + "/manage-new-articles";
                        }, 1000);
                    } else {
                        toastr.error("Something went wrong");
                    }
                    $('#add_newsletter').attr('disabled', false).text('Submit');
                },
            });
        }
    });
});


       
selectThumbnailImage.onchange = evt => {
    preview = document.getElementById('previewthumbnailimage');
    preview.style.display = 'block';
    const [file] = selectThumbnailImage.files
    if (file) {
        preview.src = URL.createObjectURL(file)
    }
}

selectImage.onchange = evt => {
    preview = document.getElementById('preview');
    preview.style.display = 'block';
    const [file] = selectImage.files
    if (file) {
        preview.src = URL.createObjectURL(file)
    }
}