internal static FormValue <bool> GetFormValue(bool isChecked, Control checkBox)
 {
     return(new FormValue <bool>(() => isChecked,
                                 () => checkBox.IsOnPage() ? checkBox.UniqueID : "",
                                 v => v.ToString(),
                                 rawValue =>
                                 rawValue == null
                                 ? PostBackValueValidationResult <bool> .CreateValidWithValue(false)
                                 : rawValue == "on" ? PostBackValueValidationResult <bool> .CreateValidWithValue(true) : PostBackValueValidationResult <bool> .CreateInvalid()));
 }
 private EwfHiddenField(string value)
 {
     formValue = new FormValue <string>(() => value,
                                        () => UniqueID,
                                        v => v,
                                        rawValue =>
                                        rawValue != null
                                                            ? PostBackValueValidationResult <string> .CreateValidWithValue(rawValue)
                                                            : PostBackValueValidationResult <string> .CreateInvalid());
 }
 public EwfFileUpload()
 {
     formValue = new FormValue <HttpPostedFile>(() => null,
                                                () => this.IsOnPage() ? UniqueID : "",
                                                v => "",
                                                rawValue =>
                                                rawValue != null
                                                                    ? PostBackValueValidationResult <HttpPostedFile> .CreateValidWithValue(rawValue.ContentLength > 0
                                                                                                                                                  ? rawValue
                                                                                                                                                  : null)
                                                                    : PostBackValueValidationResult <HttpPostedFile> .CreateInvalid());
 }
Beispiel #4
0
        /// <summary>
        /// Creates a simple HTML editor.
        /// </summary>
        /// <param name="value">Do not pass null.</param>
        /// <param name="ckEditorConfiguration">A comma-separated list of CKEditor configuration options ("toolbar: [ [ 'Bold', 'Italic' ] ]", etc.). Use this to
        /// customize the underlying CKEditor. Do not pass null.</param>
        public WysiwygHtmlEditor(string value, string ckEditorConfiguration = "")
        {
            this.ckEditorConfiguration = ckEditorConfiguration;

            formValue = new FormValue <string>(
                () => value,
                () => this.IsOnPage() ? UniqueID : "",
                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> .CreateValidWithValue(rawValue));
            });
        }
 internal static FormValue <CommonCheckBox> GetFormValue(bool allowsNoSelection, Func <IEnumerable <CommonCheckBox> > allCheckBoxesGetter,
                                                         Func <IEnumerable <CommonCheckBox> > checkedCheckBoxesGetter,
                                                         Func <CommonCheckBox, string> stringValueSelector,
                                                         Func <string, IEnumerable <CommonCheckBox> > checkedCheckBoxesInPostBackGetter)
 {
     return(new FormValue <CommonCheckBox>(() => checkedCheckBoxesGetter().FirstOrDefault(),
                                           () => {
         var firstCheckBoxOnPage = allCheckBoxesGetter().Select(i => (Control)i).FirstOrDefault(i => i.IsOnPage());
         return firstCheckBoxOnPage != null ? firstCheckBoxOnPage.UniqueID : "";
     },
                                           stringValueSelector,
                                           rawValue => {
         if (rawValue != null)
         {
             var selectedButton = checkedCheckBoxesInPostBackGetter(rawValue).SingleOrDefault();
             return selectedButton != null
                                                                                      ? PostBackValueValidationResult <CommonCheckBox> .CreateValidWithValue(selectedButton)
                                                                                      : PostBackValueValidationResult <CommonCheckBox> .CreateInvalid();
         }
         return allowsNoSelection
                                                                              ? PostBackValueValidationResult <CommonCheckBox> .CreateValidWithValue(null)
                                                                              : PostBackValueValidationResult <CommonCheckBox> .CreateInvalid();
     }));
 }