ASP.NET HTML Editor - Knowledge Base

« Back to Knowledge Base list

How to prevent empty description of an Image

Q:

I am allowing members to insert image URLs.
However I need code to make sure the user populates the image description so that the alt="" and title="" are populated always in <img> element.
So if they don't populate the description ,the image link stops, and is not inserted into the editor.
Can this be done?

A:

Put the following code block into your page:

<script type="text/JavaScript">
// When editor loaded
function EditorOnLoad(editor) { 
    // set a handler called on some loadings finished 
    editor.onLoadingEnd = onLoadingEnd;
}

// on loading finished
function onLoadingEnd(loading_type) {
    if (loading_type == "popup") { // if popup loaded
        // get the popup
        var popupObject= this._popup[this._popup.length-1];
        var popup = popupObject.iframe;
        // we need 'Image properties' popup only
        if (popup.className.indexOf("popup_image") >=0 &&
            popup.className.indexOf("popup_imageBrows") < 0) {
            var doc = popup.contentWindow.document;
            var ok = doc.getElementById("ok");  // 'OK' button element
            HTMLEditor._addEvent(ok, "mousedown"// add event handler on "mousedown"
                function(event) {
                    var title = doc.getElementById("txtAltText"); // field with the 'Alternate text'
                    if(!title.disabled) { // enabled now
                        if (title.value.length == 0) { // empty text
                            setTimeout(function() {
                                alert("Fill the 'Alternate Text' field");
                                title.focus();
                            }, 0);
                            ok.className = "dbutton"; // prevent the 'OK' button for now
                        } else {
                            ok.className = "button"; // 'enable' the button
                        }
                    }
                    return true;
            });
           
            if (!HTMLEditor.is_ie) { // add event handler on "mouseover" (if not IE)
                HTMLEditor._addEvent(ok, "mouseover",
                    function(event) {
                        var title = doc.getElementById("txtAltText"); // field with the 'Alternate text'
                        if (!title.disabled) { // enabled now
                            if (title.value.length == 0) {
                                ok.className = "dbutton"; // prevent the 'OK' button for now
                            } else {
                                ok.className = "button"; // 'enable' the button
                            }
                        }
                        return true;
                });
            }
        }
    }
}
</script>

obout.com
obout.com Home
News
HTML Editor Home
HTML Editor Home
Why the best?
Download
Site Map
Examples - 80
Appearance - 10
Full button set
Lite button set
Custom button set
Design-mode textbox
How to fit into small space
Page maker
Default font
Initially without toolbar
Preview mode
"Read only" mode New
Content - 16
Read-only and custom tags
Shadow for Image
External image gallery
Upload images
Copy/paste formatting
Preview Document appearance
Keys used for editing
.NET validation
Documents Generator
Upload documents
Convert to PDF
FullHTML
Editor and database
Spell Checker - 3
Spell checking
Spell Checker dictionaries
Several dictionaries
Localization - 2
Localization
RTL support
Integration - 9
Inside Flyout
Inside Grid
Inside Window
With Color PickerNew
Google AJAX Language API New
Inside AJAX Page
Inside CallbackPanel
MultiView
Wizard
ASP.NET AJAX ControlToolkit - 5
Collapsible panel
Tabs
Editor in each TabPanel New
Timer
Modal popup
Server-Side API - 13
Content counters
Plain text length control
Show plain text
Enable editor on focus
Set caret position on load
Add CSS files New
Hide HTML Editor until needed
FixedToolBar
CSS file for quick format
Set HTML view on load
Enable browse button for images
Enable browse button for URLs
Disable Wait message New
Server-Side Events - 5
ClickSubmit event
ClickCancel event
ContentChanged event
CallbackContent
ClientCancel
Client-Side API - 10
Working with selected text
Set design/HTML view on load
Show/hide HTML Editor
Get/set content
Surround HTML
Insert HTML
Style selected content
Exec command
Query command
'Not Set' in dropdowns New
Customize - 17
Custom editor toolbar in VS
Custom fonts
Custom font sizes
How to add icons
Custom Popup Windows
Custom Buttons
Custom Context Menu
Popup Properties Disabling
Default Table Properties
Custom toggle button
Custom select button
Textarea popup
Custom 'Quote' button New
Show/hide submit button
Show/hide Design/HTML view
Show/hide quick format panel
Width & Height
Knowledge Base - 1
Knowledge Base
Documentation - 23
Server side
HTML Editor properties & events
HTML Editor inner properties
Custom toolbar
Custom fonts
Custom font sizes
Custom Context Menu
Dictionaries for spell checker
Hot keys definition
Disabling Context Menu items
Additional CSS files New
Client side
Main functions and interfaces
Custom Context Menu support
Custom Popup Window support
Top toolbar buttons' methods
State functions
Suppress Context Menu
Spelling dictionary
Dictionary structure
Affix rules
Phonetic rules
Generate phonetic code
How to add new word
Supported browsers
ChangeLog
Tutorials - 6
Using the correct path
Autosave implementation
Full custom buttons set
Editor_data for several sites
Use with database
Template XML file use New