Last active
October 30, 2019 19:30
-
-
Save sitefinitysteve/b9f2629dae499fc3709890469c5e1486 to your computer and use it in GitHub Desktop.
EmailTextField Write.Default.cshtml - Autofill user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model Telerik.Sitefinity.Frontend.Forms.Mvc.Models.Fields.EmailTextField.EmailTextFieldViewModel | |
@using Telerik.Sitefinity.UI.MVC; | |
@using Telerik.Sitefinity.Frontend.Forms.Mvc.Helpers; | |
@using Telerik.Sitefinity.Frontend.Mvc.Helpers; | |
@using Telerik.Sitefinity.Modules.Pages; | |
@using global::Medportal.Sitefinity.Controls; | |
@using Telerik.Sitefinity.Services; | |
@using Telerik.Sitefinity.Localization; | |
@using Telerik.Sitefinity.Frontend.Forms.Mvc.StringResources | |
///######################################################################## | |
///###### Obviously remove\replace the Medportal.Sitefinity.Controls code to get the user or check anonymous | |
@{ | |
var untitledLabel = Res.Get<FieldResources>().Untitled; | |
var isSFBackend = SystemManager.CurrentHttpContext.Request.Url.AbsoluteUri.Contains("/Sitefinity"); | |
var isDesignMode = SystemManager.IsDesignMode && !SystemManager.IsPreviewMode && isSFBackend; | |
var isAuthenticated = Util.IsAnonymous ? false : true; | |
} | |
@if (!isAuthenticated && !isDesignMode) | |
{ | |
var isRequired = Model.ValidatorDefinition.Required.HasValue && Model.ValidatorDefinition.Required.Value ? "true" : "false"; | |
var hasDescription = !string.IsNullOrEmpty(Model.MetaField.Description); | |
<div class="@Model.CssClass form-group" data-sf-role="email-text-field-container"> | |
<input data-sf-role="violation-restrictions" type="hidden" value='{"maxLength":"@Model.ValidatorDefinition.MaxLength", "minLength": "@Model.ValidatorDefinition.MinLength"}' /> | |
<input data-sf-role="violation-messages" type="hidden" value='{"maxLength":"@Model.ValidatorDefinition.MaxLengthViolationMessage", "required": "@Model.ValidatorDefinition.RequiredViolationMessage", "invalid": "@Html.Resource("InvalidEntryMessage")", "regularExpression": "@Model.ValidatorDefinition.RegularExpressionViolationMessage"}' /> | |
<label class="h6" for='@Html.UniqueId("Email")'>@Model.MetaField.Title</label> | |
<input id='@Html.UniqueId("Email")' | |
data-sf-role="email-text-field-input" | |
type="@Model.InputType.ToHtmlInputType()" | |
class="form-control" | |
name="@Model.MetaField.FieldName" | |
placeholder="@Model.PlaceholderText" | |
value="@Model.Value" | |
aria-required="@isRequired" | |
@Html.Raw(Model.ValidationAttributes) | |
@{if (hasDescription) { <text> aria-describedby='@Html.UniqueId("EmailInfo") @Html.UniqueId("EmailErrorMessage")' </text> } else { <text> aria-describedby='@Html.UniqueId("TextboxErrorMessage")' </text> } } /> | |
@if (hasDescription) | |
{ | |
<p id='@Html.UniqueId("EmailInfo")' class="text-muted">@Model.MetaField.Description</p> | |
} | |
<div id='@Html.UniqueId("EmailErrorMessage")' data-sf-role="error-message" role="alert" aria-live="assertive" class="text-danger"></div> | |
</div> | |
<div> | |
@Html.Script(Url.WidgetContent("Mvc/Scripts/EmailTextField/email-text-field.js"), "bottom", false) | |
</div> | |
} | |
else if (isAuthenticated && !isDesignMode) | |
{ | |
var currentUser = global::Medportal.Sitefinity.Controls.Util.CurrentUsername; | |
<!-- Authenticated Live --> | |
<input id='@Html.UniqueId("Email")' type="hidden" name="@Model.MetaField.FieldName" value="@currentUser" /> | |
} | |
else | |
{ | |
var currentUser = global::Medportal.Sitefinity.Controls.Util.CurrentUsername; | |
<!-- Design mode --> | |
<div class="sf-fieldWrp form-group"> | |
<label for='@Html.UniqueId("HiddenField")'> | |
@if (string.IsNullOrEmpty(Model.MetaField.FieldName)) | |
{ | |
@untitledLabel; | |
} | |
else | |
{ | |
@Model.MetaField.FieldName; | |
} | |
</label> | |
<input id='@Html.UniqueId("Email")' type="text" class="form-control" name="@Model.MetaField.FieldName" value="@currentUser" disabled="disabled" /> | |
</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment