[CLOSED] Set HTMLEditor as a Mandatory field

  1. #1

    [CLOSED] Set HTMLEditor as a Mandatory field

    Hi Team,

    In my project we use Coolite HTML Editor, we want to set this Field as Mandatory one how can i check the field, becuase when i get the text it gives me HTML code even if there is no string it gives me "" tag some times, pls help me on this.
    Last edited by Daniil; Jan 09, 2011 at 12:15 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Unfortunately, HtmlEditor doesn't support standard Ext.form.Filed validation mechanism (respectively, there is no AllowBlank property).

    So, it needs to manually validate this field when you need.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    
        <script type="text/javascript">
            var isHtmlEditorValid = function (editor) {
                var value = editor.getValue();
                return !Ext.isEmpty(value) && !(value.toLowerCase() == Ext.util.Format.htmlEncode("<div></div>"));
            }
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:HtmlEditor ID="HtmlEditor1" runat="server" />
        <ext:Button runat="server" Text="Is valid?">
            <Listeners>
                <Click Handler="alert(isHtmlEditorValid(HtmlEditor1));" />
            </Listeners>
        </ext:Button>
        </form>
    </body>
    </html>
  3. #3
    For anyone who might be interested. This is a possible solution for AllowBlank validation of HtmlEditor.

    The example is done and tested for Ext.NET v2. Though, it might work with v1 and v3 with, maybe, some slight changes.

    Example
    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    
        <script>
            Ext.form.field.HtmlEditor.override({
                getErrors: function () {
                    var errors = [],
                        v;
    
                    if (!this.allowBlank) {
                        v = this.getValue();
    
                        if (Ext.isEmpty(v) || v === "<br>" || v === "<div><div>" || v === "<p></p>") {
                            errors.push(this.blankText || Ext.form.field.Text.prototype.blankText);
                        }
                    }
    
                    return errors;
                },
    
                isValid: function () {
                    var valid = this.callParent(arguments);
    
                    if (valid) {
                        this.iframeEl.applyStyles({
                            "border-color": null,
                            "border-width": null,
                            "border-style": null
                        });
                    } else {
                        this.iframeEl.applyStyles({
                            "border-color": "#cc3300",
                            "border-width": "1px",
                            "border-style": "solid"
                        });
                    }
    
                    return valid;
                }
            });
    
            var onInitialize = function (editor) {
                Ext.EventManager.on(editor.getDoc(), Ext.isGecko ? "keypress" : "keydown", function () {
                    this.isValid();
                }, editor, { buffer: 150 })
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:HtmlEditor 
                ID="HtmlEditor1" 
                runat="server" 
                Width="600" 
                AllowBlank="false">
                <Listeners>
                    <Initialize Fn="onInitialize" />
                </Listeners>
            </ext:HtmlEditor>
    
            <ext:Button 
                runat="server" 
                Text="Validate" 
                Handler="App.HtmlEditor1.isValid();" />
        </form>
    </body>
    </html>

Similar Threads

  1. Replies: 1
    Last Post: Apr 09, 2012, 5:03 PM
  2. [CLOSED] Mandatory Field Indicator displayed inside combobox
    By AnulekhaK in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Jan 31, 2012, 8:12 AM
  3. HTMLEditor on Editor Field
    By pankyhehe in forum 1.x Help
    Replies: 0
    Last Post: Dec 29, 2011, 9:03 AM
  4. Replies: 32
    Last Post: Nov 17, 2010, 12:08 PM
  5. [CLOSED] [1.0] Get all mandatory fields always in red
    By juane66 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 27, 2010, 2:14 PM

Tags for this Thread

Posting Permissions