#Html.TextBoxFor textbox isn't highlighted after failing validation - asp.net-mvc-3

I am using MVC3 with Razor. For input I have two types of control:
#Html.TextBoxFor
#Html.TextAreaFor
Both have required field validation. #Html.TextAreaFor highlight the box if validation fails where as #Html.TextBoxFor does not.
Here is my code
HTML:
#Html.TextBoxFor(m => m.FirstName)
Model:
[Required(ErrorMessage = "First Name is required")]
public string FirstName { get; set; }
Why is the textbox created using #Html.TextBoxFor not hightlighted when its validation fails?

Make sure the variables you're assigning to these input fields are [Required] in your model class.. Also did you strip out any css in a "clean up" process? Try adding this if it's not in there.
.field-validation-error
{
color: #ff0000;
}
.field-validation-valid
{
display: none;
}
.input-validation-error
{
border: 1px solid #ff0000;
background-color: #ffeeee;
}
.validation-summary-errors
{
font-weight: bold;
color: #ff0000;
}
.validation-summary-valid
{
display: none;
}

I had this problem myself. I added a new CSS class to the Site.css file (or whatever style sheet you prefer).
textarea.input-validation-error {
border: 1px solid #e80c4d;
}

I faced same issue today:
In order to raise validation for textbox or any other field you just need these two lines:
In controller: ModelState.AddModelError("ErrorEmail", "Error Message");
In View: #Html.ValidationMessage("ErrorEmail")
And in web.config
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
It was overwriting validation css with my own website css so that's why it was not showing red border around textbox.
making validation error style important resolved my problem:
input.input-validation-error {
border: 1px solid #e80c4d !important;
}

Add both .input-validation-error and .input.input-validation-error classes.

I know this is old, but in case anyone else is searching this, ensure you also use
#Html.ValidationMessageFor(m => m.FirstName)
After your textbox

In order to have client-side validation, you need to ensure that you have the necessary scripts included in your View (whether it is through the _Layout.cshtml view or your direct view). Put this at the top of your view:
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
Ensure the path and the script names are correct. This will enable you to utilize client-side validation (i.e. highlighting the text box).

Related

Attribute selector doesnt work

Im trying to select img tags based on the alt attribute to load proper background-image on mobile
the problem is not matter what combination of attribute selector I use it seems it doesnt work, I cant even select the tag I want with it
I used these
img[alt="Chelo Kebab"] {opacity: 0.5}
img[alt*="Chelo Kebab"] {opacity: 0.5}
img[alt^="Chelo Kebab"] {opacity: 0.5}
i used all combinations, capital, normal even I tried
img[alt] {opacity: 0.5}
but no success
also I tried to put parent class name before img
you can see the code Im working on in this address
here
Im trying to select each img tag
here is the proof that I write everything correct
UPDATE Its obvious now its a CACHeING problem, Im trying to solve
There is no problem with attribute-selectors for iamges in css:
img[alt="abc"] {
opacity: 0.8 !important;
}
img[alt="def"] {
opacity: 0.5 !important;
}
img[alt="ghi"] {
opacity: 0.3 !important;
}
img[alt] {
opacity: 0.1;
}
<img src="https://dummyimage.com/200x100/000/fff" /><br />
<img alt="abc" src="https://dummyimage.com/200x100/000/fff" /><br />
<img alt="def" src="https://dummyimage.com/200x100/000/fff" /><br />
<img alt="ghi" src="https://dummyimage.com/200x100/000/fff" /><br />
Note that because you have a more general selector in your code (img[alt]) I added the !important to the properties to override the opacity in your general selector.

Scout Eclipse Neon margin on fields

Is it possible to set a margin around fields.
For example in image :
If I want to set lower (separated) checkBox in line with above once, is there a way to do it?
Marko
Start by inspecting the HTML code (with Chrome).
The code corresponding to the Checkbox Field is something like that:
<div class="form-field check-box-field"
data-modelclass="org.eclipse.scout.widgets.client.ui.forms.CheckboxFieldForm$MainBox$ConfigurationBox$CheckboxField"
data-classid="CheckboxField_org.eclipse.scout.widgets.client.ui.forms.CheckboxFieldForm"
id="scout.CheckBoxField[1-49]"
style="left: 0px; top: 14px; width: 1598px; height: 30px;"
>
<div class="field has-inner-alignment halign-left valign-top" style=
"left: 148px; top: 0px; width: 1420px; height: 30px;">
<div class="check-box" tabindex="0"></div>
<div class="label">
Checkbox
</div>
</div>
</div>
With CSS you can do anything possible:
.check-box-field {
background-color: red;
}
Now because you do not want to add some custom CSS style for all CheckBox Fields, you can define a custom Css-Class in your CheckBox:
#Order(4)
public class UnknownCheckBox extends AbstractBooleanField {
#Override
protected String getConfiguredCssClass() {
return "checkbox-under-listbox";
}
// ... Some Code ...
}
And now you add this CSS code:
.checkbox-under-listbox {
margin-left: 20px;
}
I have realized this example with the Widgets Demo Application (org.eclipse.scout.docs repository, releases/5.2.x branch). I added my css code in this file: org.eclipse.scout.widgets.ui.html/src/main/js/widgets/main.css (It is probably not the best approach to have everything in main.css).
You can deduce from this example how you can add an additional CSS/LESS module and macro to your application. This post: Inclusion of additional icons from font-awesome might also be usefull. You will have a main.css instead of a font.css.
WARNING: this is not state of the art.
At the end this is normal HTML development (single page application of course), so you can do what you want...
If you do not want to use the LESS compiler and the File preprocessor, you can simpelly add a normal CSS file in the folder:
<your_project>.ui.html/src/main/resources/WebContent
Let say:
<your_project>.ui.html/src/main/resources/WebContent/my_custom.css
Do not forget to include your CSS File between the <head> and </head> tags in the HTML index file:
<your_project>.ui.html/src/main/resources/WebContent/index.html
Something like:
<head>
<!-- some code -->
<link rel="stylesheet" type="text/css" href="my_custom.css">
<scout:stylesheet src="res/scout-module.css" />
<!-- some code -->
</head>
You can always use custom CSS: Let your field implement IStyleable and use setCssClass() to apply an appropriate CSS class. I'd try to avoid using such pixel pushing approaches as much as possible.

Hover link to change opacity of image

I am trying to get the effect shown here https://www.kogevitamins.com/
Where you hover over the "learn more" link to get the opacity of the image to also change.
Thanks.
Edit:
Right now I have
for HTML
<img src="/images/pill.png" alt="description" id ="image" />
<p> Daily Essentials </p>
<a id ="button" href="#">Learn More</a>
For jquery
$("#button").hover(function(){
$("#image").animate({opacity:1},300);
}).mouseout(function(){
$("#image").animate({opacity:0.6},300);;
});
It doesn't seem to work so far
Edit:
I have the following code recently updated but the hover on effect doesn't work for me. Heres a link to the thing I'm trying to get to work http://maninkorean.com/
<div class ="product-content">
<img class="imgClass" src="/images/pill.png" alt="description" />
<p> Daily Essentials </p>
<a id ="button" href="#">Learn More</a>
</div>
$("a#button, img").hover(function(){
$("img.imgClass").animate({opacity:1},300);
}).mouseout(function(){
$("img.imgClass").animate({opacity:0.6},300);;
});
img.imgClass{
opacity: 0.6
}
#button {
padding: 10px 24px;
background:#F15951;
border: medium none;
border-radius: 3px 3px 3px 3px;
color:white;
margin-top:50px;
margin-bottom:50px;
font-weight: bold;
}
You should be able to do this using jQuery with the following code:
$('#id of link you want to use to change opacity').hover(function() { $('#id of image that you want to change opacity of').css({ 'opacity' : 0.25 }); });
Combine JQuery and CSS3's opacity features to wire up an "OnHover" event to the images that changes the opacity of the said image.
http://www.css3.info/preview/opacity/
Unless you want to see through those images and show background pattern, there is no need to deal with opacity.
Even though you can prepare semitransparent version of image and change src attribute in onMouseOver event.
But you can achieve the same effect by simply putting a div with 1-pixel semitransparent background above selected image.
Using CSS opacity will cut off older browsers.
Hi You can easily do this by css, with somethings like this:
.img {opacity:0.4; /*some more css*/ } /* (opacity:) is now supported by all browsers */
.img:hover {opacity:0.98; /* Some more css be creative... */ }
That's all!
Here's some html, css, jquery that shows how to do it:
<div></div><a>Hover On Me</a>
div{
width:300px;
height:300px;
display:block;
background:red;
opacity: 0.6
}
a{
display:block;
margin-top:20px;
width:100px;
padding:5px;
height:20px; border-radius:5px;
background:yellow;
}
$("a").hover(function(){
$("div").animate({opacity:1},300);
}).mouseout(function(){
$("div").animate({opacity:0.6},300);
});
http://jsfiddle.net/Rd5Yy/2/
It looks like in the specific example you cite, they've used CSS3 transitions. See here for a tutorial: http://www.w3schools.com/css3/css3_transitions.asp
In a nutshell using these you can do all kind of funky effects without any javascript. CSS3 is supported by modern browsers (but is pretty cutting edge as web technologies go) and isn't yet a W3C standard.
This code should do what you wanted to do (I tested it against your HTML):
$(document).ready(function() {
$("#button").hover(function(){
$("#image").animate({opacity:0.6},300);
}).mouseout(function(){
$("#image").animate({opacity:1},300);;
});
});
Okay, I just checked out your page. Firstly, it looks like jQuery is not working through the $ on your site, so you'll need to either troubleshoot that, or use it by jQuery instead. I pasted this code in on the JavaScript console on your site and it works:
jQuery("a#button, img").hover(function(){
jQuery("img.imgClass").animate({opacity:1},300);
}).mouseout(function(){
jQuery("img.imgClass").animate({opacity:.6},300);;
});
edit: Looks like you got it working as I was typing up this response

Juice UI droppable example - clueless newbie can't get workage happening

Sorry, total Juice UI newbie, and really a web app newbie as well. Having trouble getting the simple example working from the Juice UI website. It is supposed to illustrate how easy it is to make a drag-drop example, but I get a lot of errors which makes me think I'm missing something really basic. I'm trying to use the Droppable control, documented here:
http://juiceui.com/controls/droppable
The draggable example worked fine, so I've gotten that far, but when I paste the droppable example text into my C# web application, I get errors that the style needs to be outside the form, outside the body, etc - I keep moving it up the chain. Eventually it says "element style needs to be in a parent element" - not sure where to put it if I can't put it on the page. I suppose in a .css file? Also, it says the tag is missing a required attribute 'type'.
Any help would be much appreciated!
<style>
.draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
.droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }
</style>
<script>
$(function(){
$( "#_Default" ).droppable( "option", "drop", function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Dropped!" );
}
);
});
</script>
<asp:panel ID="_Draggable" CssClass="draggable ui-widget-content" runat="server">
<p>Drag me to my target</p>
</asp:panel>
<juice:draggable TargetControlID="_Draggable" runat="server"/>
<asp:panel ID="_Default" CssClass="droppable ui-widget-header" runat="server" ClientIDMode="Static">
<p>Drop here</p>
</asp:panel>
<juice:droppable TargetControlID="_Default" runat="server"/>
The document you're reviewing is a partial document. I believe it assumes you have the rest of the document already authored:
<!DOCTYPE html>
<html>
<head>
<title>Droppable Example</title>
</head>
<body>
<!-- Your Code Here -->
</body>
</html>
Okay, a little research revealed:
element always goes inside the section - duh
the type attribute for always needs to be type="text/css",
so I added that
Added the type attribute for the (type="text/javascript")
Another error popped up, conflict with the _Default id in the
example, same as the Default class name when you create a new web
application. Bad choice of element ID for an example in which the
user will likely be doing exactly what I was doing, creating a
default web app and pasting in the code and expecting it to run.
Don't know why none of these errors were caught when this example was written, but kind of frustrating first experience with Juice UI. Thanks all for your time and responses.

Button image for sitecore marketer module

I want to change submit button of Web Forms for Marketers module with image in Sitecore.
Thank in advance
You can change the button by updating contents of the following file:
\sitecore modules\Web\Web Forms for Marketers\Control\SitecoreSimpleFormAscx.ascx
Replace
<wfm:FormSubmit ID="submit" runat="server" Class="scfSubmitButtonBorder"/>
with you own custom control (which can contain Image / LinkButton / whatever)
It sounds like you are trying to change the submit button into an <input type="image" />. I have not found a way to do this with WFFM. You can style the submit button, or you can export the form to ASCX and make the change to an image yourself.
You can do quite a bit with CSS styling of <input type="submit" />.
http://www.456bereastreet.com/lab/styling-form-controls-revisited/submit-button/
You can change the button style in Default.css.
Use background-image to add the image.
Below example use an image as background for the Submit button in WFFM:
.scfSubmitButtonBorder
{
background-image: url(/images/bg_button.png);
padding-left: 5px;
float: right;
margin-bottom: 10px;
}
.scfSubmitButtonBorder input
{
border: none;
padding: 0 5px 0 0;
color: white;
font: 14px/14px FrutigerRoman, Arial !important;
width: 100px;
height: 30px;
background-image: url(/images/bg_button.png);
background-position: right -30px;
background-color: transparent;
cursor: pointer;
}
I suppose you're talking about Web Forms for Marketers module, aren't you? It is not clear from your initial question...
Anyway, in Form designer you can select the submit button and you'll its properties on the left side. Among various properties, the very first is the edit box called "Button Name" . Put the desired text for the Submit button there.
Here's how I did it.
First, create a custom control:
namespace Sitecore.Custom.Controls
{
public class ImageSubmitButton : Sitecore.Form.Web.UI.Controls.SubmitButton
{
public string ImageUrl { get; set; }
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
if (string.IsNullOrEmpty(ImageUrl) == false)
{
writer.AddAttribute("type", "image");
writer.AddAttribute("src", ResolveUrl(ImageUrl));
}
// This won't overwrite our explicit type="image"
base.AddAttributesToRender(writer);
}
}
}
Export the form as ASCX in sitecore, use the Developer Center to create a new Sublayout and copy the exported ASCX code into this file. First, register a new prefix
<%# Register TagPrefix="ctrl" Namespace="Sitecore.Custom.Controls" Assembly="<AssemblyName>" %>
Finally, change
<cc0:submitbutton runat="server" onclientclick="$scw.webform.lastSubmit = this.id;" text="Submit" validationgroup="..." cssclass="..." id="..." onclick="OnClick" >
</cc0:submitbutton>
to
<ctrl:ImageSubmitButton ImageUrl="~/imgs/button.png" runat="server" OnClientClick="$scw.webform.lastSubmit = this.id;"
Text="Submit" validationgroup="..." cssclass="..." id="..."
OnClick="OnClick"></ctrl:ImageSubmitButton>
Finally, replace the form in your item with the sublayout.

Resources