private Box test1(DataModification dm, Action <string> setValue) { var box = new EwfTextBox(""); box.SetupAutoComplete(TestService.GetInfo(), AutoCompleteOption.NoPostBack); var dv = new DataValue <string>(); dm.AddTopValidationMethod((pbvd, validator) => dv.Value = box.GetPostBackValue(pbvd)); dm.AddModificationMethod(() => setValue(dv.Value)); return (new Box( "Autofill behavior. Typing more than 3 characters should bring up autofill options from a web service. " + "Selecting an item or changing the text will no cause a post-back. This value show appear when submitting the page's submit button.", box.ToSingleElementArray())); }
/// <summary> /// Creates a simple HTML editor. /// </summary> /// <param name="value">Do not pass null.</param> /// <param name="allowEmpty"></param> /// <param name="validationMethod">The validation method. Do not pass null.</param> /// <param name="setup">The setup object for the HTML editor.</param> /// <param name="maxLength"></param> public WysiwygHtmlEditor( string value, bool allowEmpty, Action <string, Validator> validationMethod, WysiwygHtmlEditorSetup setup = null, int?maxLength = null) { setup = setup ?? new WysiwygHtmlEditorSetup(); var id = new ElementId(); FormValue <string> formValue = null; formValue = new FormValue <string>( () => value, () => setup.IsReadOnly ? "" : id.Id, v => v, rawValue => { if (rawValue == null) { return(PostBackValueValidationResult <string> .CreateInvalid()); } // This hack prevents the NewLine that CKEditor seems to always add to the end of the textarea from causing // ValueChangedOnPostBack to always return true. if (rawValue.EndsWith(Environment.NewLine) && rawValue.Remove(rawValue.Length - Environment.NewLine.Length) == formValue.GetDurableValue()) { rawValue = formValue.GetDurableValue(); } return(PostBackValueValidationResult <string> .CreateValid(rawValue)); }); var modificationValue = new PageModificationValue <string>(); component = new ElementComponent( context => { id.AddId(context.Id); var displaySetup = setup.DisplaySetup ?? new DisplaySetup(true); var jsShowStatements = getJsShowStatements(context.Id, setup.CkEditorConfiguration); displaySetup.AddJsShowStatements(jsShowStatements); displaySetup.AddJsHideStatements("CKEDITOR.instances.{0}.destroy(); $( '#{0}' ).css( 'display', 'none' );".FormatWith(context.Id)); return(new ElementData( () => { var attributes = new List <Tuple <string, string> >(); if (setup.IsReadOnly) { attributes.Add(Tuple.Create("disabled", "disabled")); } else { attributes.Add(Tuple.Create("name", context.Id)); } if (!displaySetup.ComponentsDisplayed) { attributes.Add(Tuple.Create("style", "display: none")); } return new ElementLocalData( "textarea", attributes: attributes, includeIdAttribute: true, jsInitStatements: displaySetup.ComponentsDisplayed ? jsShowStatements : ""); }, children: new TextNode(() => EwfTextBox.GetTextareaValue(modificationValue.Value)).ToCollection())); }, formValue: formValue); validation = formValue.CreateValidation( (postBackValue, validator) => { if (setup.ValidationPredicate != null && !setup.ValidationPredicate(postBackValue.ChangedOnPostBack)) { return; } var errorHandler = new ValidationErrorHandler("HTML"); var validatedValue = maxLength.HasValue ? validator.GetString(errorHandler, postBackValue.Value, allowEmpty, maxLength.Value) : validator.GetString(errorHandler, postBackValue.Value, allowEmpty); if (errorHandler.LastResult != ErrorCondition.NoError) { setup.ValidationErrorNotifier(); return; } validationMethod(validatedValue, validator); }); formValue.AddPageModificationValue(modificationValue, v => v); }
void ControlTreeDataLoader.LoadData() { Attributes.Add("name", UniqueID); PreRender += delegate { EwfTextBox.AddTextareaValue(this, formValue.GetValue(AppRequestState.Instance.EwfPageRequestState.PostBackValues)); }; }