4444
4545 <div class =" mb-3" >
4646 <label class =" form-label mb-1 fs-14 fw-medium" >
47- Post Created Date
47+ Post Create Date
4848 </label >
4949 <input class =" form-control fs-14" type =" date" name =" postCreatedDate" id =" postCreatedDate" value =" " >
5050 </div >
107107 </div >
108108 </div >
109109 <div class =" col-lg-4 col-12" >
110- <div class =" bg-white rounded-5 shadow-sm mt-4 p-4" >
111- <h1 class =" text-center fs-24 fw-bold" >Preview</h1 >
110+ <h4 class =" mb-3" >Live Preview</h4 >
111+ <div id =" previewContent" class =" p-3 border rounded bg-white" >
112+ <h2 id =" previewTitle" class =" fs-20 fw-bold mb-3 text-primary" ></h2 >
113+ <div id =" previewMeta" class =" mb-3" >
114+ <div id =" previewCategories" class =" mb-1" ></div >
115+ <div id =" previewTags" ></div >
116+ </div >
117+ <div id =" previewBody" class =" border p-3 rounded bg-light" ></div >
112118 </div >
113119 </div >
114120 </div >
143149 const postTags = document .getElementById (' postTags' );
144150 const content = document .getElementById (' content' );
145151 const editor = document .getElementById (" editor" );
152+ const tagInput = document .getElementById (" tagInput" );
153+ const toolbar = document .getElementById (' toolbar-container' );
146154
147155 // Check if it's a draft submission
148156 const isDraft = document .getElementById (" isDraft" ).value === " 1" ;
149157
150158 // Reset validation styles
151- [title, categoryId, posttypeId, postTags].forEach (field => field .classList .remove (" is-invalid" ));
159+ [title, categoryId, posttypeId, tagInput].forEach (field => field .classList .remove (" is-invalid" ));
160+ toolbar .classList .remove (" border-danger" );
152161 editor .classList .remove (" border-danger" );
153162
154163 // Validate fields only if it's NOT a draft
167176 }
168177 if (postTags .value .trim () === " " ) {
169178 isValid = false ;
170- postTags .classList .add (" is-invalid" );
179+ tagInput .classList .add (" is-invalid" );
180+ tagInput .classList .remove (" border-0" );
171181 }
172182 if (content .value .trim () === " <p><br></p>" || content .value .trim () === " " ) {
173183 isValid = false ;
184+ toolbar .classList .add (" border-danger" );
174185 editor .classList .add (" border-danger" );
175186 }
176187 }
177188
178189 if (! isValid) {
179190 event .preventDefault ();
180- alert ( " Please fill out all required fields." );
191+ notifier . show ( ' Error! ' , ' Please fill out all required fields.' , ' ' , ' images/high_priority-48.png ' , 4000 );
181192 return false ;
182193 }
183194 });
247258 function updateHiddenTags () {
248259 postTags .value = tags .join (" ," );
249260 }
261+
262+ // Live preview logic
263+ function updatePreview () {
264+ // Title
265+ const title = document .getElementById (" title" ).value ;
266+ document .getElementById (" previewTitle" ).innerText = title;
267+
268+ // Content
269+ document .getElementById (" previewBody" ).innerHTML = quill .root .innerHTML .trim ();
270+
271+ // Categories
272+ const categorySelect = document .getElementById (" categoryId" );
273+ const selectedCategories = Array .from (categorySelect .selectedOptions ).map (opt => opt .text );
274+ const previewCategories = document .getElementById (" previewCategories" );
275+ previewCategories .innerHTML = ' ' ;
276+ selectedCategories .forEach (cat => {
277+ const badge = document .createElement (" span" );
278+ badge .className = " badge bg-primary me-1 mb-1" ;
279+ badge .textContent = cat;
280+ previewCategories .appendChild (badge);
281+ });
282+
283+ // Tags
284+ const previewTags = document .getElementById (" previewTags" );
285+ previewTags .innerHTML = ' ' ;
286+ tags .forEach (tag => {
287+ const badge = document .createElement (" span" );
288+ badge .className = " badge bg-secondary me-1 mb-1" ;
289+ badge .textContent = tag;
290+ previewTags .appendChild (badge);
291+ });
292+ }
293+
294+ // Event listeners
295+ document .getElementById (" title" ).addEventListener (" input" , updatePreview);
296+ document .getElementById (" categoryId" ).addEventListener (" change" , updatePreview);
297+ quill .on (' text-change' , updatePreview);
250298 });
251-
252299 </script >
253300</main >
0 commit comments