protected internal virtual void renderDatePicker(FormField formField, HtmlDocumentBuilder documentBuilder) { bool isReadOnly = isReadOnly(formField); // start input-group HtmlElementWriter inputGroupDivElement = (new HtmlElementWriter(DIV_ELEMENT)).attribute(CLASS_ATTRIBUTE, INPUT_GROUP_CLASS); string formFieldId = formField.Id; // <div> documentBuilder.startElement(inputGroupDivElement); // input field HtmlElementWriter inputField = createInputField(formField); if (!isReadOnly) { inputField.attribute(DATEPICKER_POPUP_ATTRIBUTE, DATE_FORMAT).attribute(IS_OPEN_ATTRIBUTE, string.format(DATE_FIELD_OPENED_ATTRIBUTE, formFieldId)); } // <input ... /> documentBuilder.startElement(inputField).endElement(); // if form field is read only, do not render date picker open button if (!isReadOnly) { // input addon HtmlElementWriter addonElement = (new HtmlElementWriter(DIV_ELEMENT)).attribute(CLASS_ATTRIBUTE, INPUT_GROUP_BTN_CLASS); // <div> documentBuilder.startElement(addonElement); // button to open date picker HtmlElementWriter buttonElement = (new HtmlElementWriter(BUTTON_ELEMENT)).attribute(TYPE_ATTRIBUTE, BUTTON_BUTTON_TYPE).attribute(CLASS_ATTRIBUTE, BUTTON_DEFAULT_CLASS).attribute(NG_CLICK_ATTRIBUTE, string.format(OPEN_DATEPICKER_FUNCTION_SNIPPET, formFieldId)); // <button> documentBuilder.startElement(buttonElement); HtmlElementWriter iconElement = (new HtmlElementWriter(I_ELEMENT)).attribute(CLASS_ATTRIBUTE, CALENDAR_GLYPHICON); // <i ...></i> documentBuilder.startElement(iconElement).endElement(); // </button> documentBuilder.endElement(); // </div> documentBuilder.endElement(); HtmlElementWriter scriptElement = (new HtmlElementWriter(SCRIPT_ELEMENT)).attribute(CAM_SCRIPT_ATTRIBUTE, null).attribute(TYPE_ATTRIBUTE, TEXT_FORM_SCRIPT_TYPE).textContent(string.format(OPEN_DATEPICKER_SNIPPET, formFieldId, formFieldId)); // <script ...> </script> documentBuilder.startElement(scriptElement).endElement(); } // </div> documentBuilder.endElement(); }
protected internal virtual string renderFormData(FormData formData) { if (formData == null || (formData.FormFields == null || formData.FormFields.Count == 0) && (formData.FormProperties == null || formData.FormProperties.Count == 0)) { return(null); } else { HtmlElementWriter formElement = (new HtmlElementWriter(FORM_ELEMENT)).attribute(NAME_ATTRIBUTE, GENERATED_FORM_NAME).attribute(ROLE_ATTRIBUTE, FORM_ROLE); HtmlDocumentBuilder documentBuilder = new HtmlDocumentBuilder(formElement); // render fields foreach (FormField formField in formData.FormFields) { renderFormField(formField, documentBuilder); } // render deprecated form properties foreach (FormProperty formProperty in formData.FormProperties) { renderFormField(new FormPropertyAdapter(formProperty), documentBuilder); } // end document element documentBuilder.endElement(); return(documentBuilder.HtmlString); } }
protected internal virtual void renderSelectBox(FormField formField, HtmlDocumentBuilder documentBuilder) { HtmlElementWriter selectBox = new HtmlElementWriter(SELECT_ELEMENT, false); addCommonFormFieldAttributes(formField, selectBox); // <select ...> documentBuilder.startElement(selectBox); // <option ...> renderSelectOptions(formField, documentBuilder); // </select> documentBuilder.endElement(); }
protected internal virtual void renderFormField(FormField formField, HtmlDocumentBuilder documentBuilder) { // start group HtmlElementWriter divElement = (new HtmlElementWriter(DIV_ELEMENT)).attribute(CLASS_ATTRIBUTE, FORM_GROUP_CLASS); documentBuilder.startElement(divElement); string formFieldId = formField.Id; string formFieldLabel = formField.Label; // write label if (!string.ReferenceEquals(formFieldLabel, null) && formFieldLabel.Length > 0) { HtmlElementWriter labelElement = (new HtmlElementWriter(LABEL_ELEMENT)).attribute(FOR_ATTRIBUTE, formFieldId).textContent(formFieldLabel); // <label for="...">...</label> documentBuilder.startElement(labelElement).endElement(); } // render form control if (isEnum(formField)) { // <select ...> renderSelectBox(formField, documentBuilder); } else if (isDate(formField)) { renderDatePicker(formField, documentBuilder); } else { // <input ...> renderInputField(formField, documentBuilder); } renderInvalidMessageElement(formField, documentBuilder); // end group documentBuilder.endElement(); }
protected internal virtual void renderInvalidMessageElement(FormField formField, HtmlDocumentBuilder documentBuilder) { HtmlElementWriter divElement = new HtmlElementWriter(DIV_ELEMENT); string formFieldId = formField.Id; string ifExpression = string.format(INVALID_EXPRESSION + " && " + DIRTY_EXPRESSION, formFieldId, formFieldId); divElement.attribute(NG_IF_ATTRIBUTE, ifExpression).attribute(CLASS_ATTRIBUTE, HAS_ERROR_CLASS); // <div ng-if="....$invalid && ....$dirty"...> documentBuilder.startElement(divElement); if (!isDate(formField)) { renderInvalidValueMessage(formField, documentBuilder); renderInvalidTypeMessage(formField, documentBuilder); } else { renderInvalidDateMessage(formField, documentBuilder); } documentBuilder.endElement(); }