Location of Validation Message - asp.net-mvc

In this guide that I was attempting to follow, validation messages show up to the right and are red. Mine appear dull and to the left, as in the picture below.
I have read and reread the guide I linked to, but I can't see any major difference between his code and mine. Why do my Label and TextBox show up in the order I created them, while my validation messages show up in between?
Here is (what I believe to be) the relevant part of my model
[Required(ErrorMessage = "Required")]
[Display(Name="IP Address")]
public string address { get; set; }
[Required(ErrorMessage = "Required")]
[Display(Name = "TCP Port")]
public int port { get; set; }
and the corresponding part of my View.
<p>
#Html.LabelFor(c => c.address):
#Html.TextBoxFor(c => c.address)
#Html.ValidationMessageFor(c => c.address)
</p>
<p>
#Html.LabelFor(c => c.port):
#Html.TextBoxFor(c => c.port)
#Html.ValidationMessageFor(c => c.port)
</p>
I realize that typical validation on items like these would be more robust. For now, my only concern is that they did not leave the field blank.

Have you tried adding this to your main css file?
.input-validation-error
{
border: 1px solid #ff0000;
background-color: #ffeeee;
}
.field-validation-error {
background-color:white;
border-radius:4px;
border: solid 1px #333;
display: block;
position: absolute;
top:0; right:0; left:0;
text-align:right;
}

I was having a similar issue. The validation message for my first input box was right aligned while all the rest were left aligned. Updating my style sheet with the code below fixed the problem.
.field-validation-error {
display: block;
text-align:right;
}

The Input boxes were somehow given the property float: right. The validation messages, by default, float left. By removing the float property of the Inputs, the validation messages are now showing up to the right of the Inputs.
Furthermore, by pressing F12 in the browser while the project is running, one can view the styles being applied to elements. Additionally, one can just right-click the element and "inspect element". I at least confirmed that alternative in Chrome and IE10.
Hopefully that trick will help someone else avoid looking at MVC for problems caused by a ninja CSS.

Related

Angular: Mat-card keyboard navigation

I am trying to make a mat-card navigable from the keyboard. Right now, when pressing tab the element is focused however the redirect event (should be the same as the click event) isn't triggered when pressing enter.
I've tried keydown.enter and onKeyDown (from a11y package) but no success so far.
HTML
<mat-card role="group" (click)="addQueryParam(group.name)" (keydown.enter)="addQueryParam(group.name)" class="mat-elevation-z0"
[ngClass]="'background-'+index" (mouseout)="mouseOver=false"
(mouseover)="mouseOver=true" style="padding: none; margin: 5px">
Typescript
addQueryParam(groupName) {
this.router.navigate(['/data'], { queryParams: { ['groups.title']: groupName }, queryParamsHandling: 'merge' });
}
Any idea how to solve this issue?
TIA,
Isabela
I suggest you two things:
try using (keyup.enter)=.... I used it a couple of times and it worked well
If that doesn't work try using (keyup) or (keydown) and in your function check if the key code is 13 (enter key code), something like this:
HTML
<mat-card role="group" (click)="addQueryParam(group.name)" (keydown)="addQueryParam($event, group.name)" class="mat-elevation-z0"
[ngClass]="'background-'+index" (mouseout)="mouseOver=false"
(mouseover)="mouseOver=true" style="padding: none; margin: 5px">
Typescript:
addQueryParam($event, groupName) {
if($event.keyCode === 13){
this.router.navigate(['/data'], { queryParams: ...);
}
}
If i remember correctly you can check the type of the event in a field like event.type, or something like that.
Additionally check this discussion out, because theese functions are not well documented, and here you can find som infos :
What are the options for (keyup) in Angular2?
EDIT
I also found this very useful article: https://medium.com/claritydesignsystem/angular-pseudo-events-d4e7f89247ee

Datatable (without pagination) > missing parameters in form submit

#3 EDIT => CAUSE FOUND!
So I found that what is causing the issue is Datatable. Even if I'm not using pagination, Datatable is limiting the number of rows the form can POST.
jQuery('#tblStats').DataTable( {
dom: 'ft',
ordering: false,
jQueryUI: true,
scrollY: "400px",
deferRender: true,
scroller: true,
scrollCollapse: true,
language: {
search: "<%= t('app.bouton.filter') %>",
infoEmpty: "<%= t('app.datetables.sZeroRecords') %>"
}
});
Any ideas on how to avoid that limit and continue using Datatable?
I've already tried this but still the same:
https://www.gyrocode.com/articles/jquery-datatables-how-to-submit-all-pages-form-data/
Thanks!
INITIAL MESSAGE
I'm having a hard time trying to figure out why I have some missing parameters when submitting a form.
Inside the form there is a table that is dynamically populated. 10 parameters are sent for each row. The submit works fine with small data but it seems to have a limit at 1898 parameters. Some times the parameters of the first 5 or 6 rows are missing and some times are the parameters of the last rows. This is totally random. But the limit seems to be always the same: no more than 1898 parameters are sent.
I get no error at all. The parameters are just not sent. This is happening in production server as well than in development server. The servers are different and the OS is different as well.
Rails version is 2.3.18. Ruby version is 1.8.7.
Does anyone have any idea of what's going on?
Thanks in advance for your help!
#1 EDIT
Following the advice of Oshanz I have found passenger's config file. In my case:
$>/home/alberto/.rvm/gems/ree-1.8.7-2012.02#dev/gems/passenger-4.0.37/resources/templates/standalone/config.erb
In the file there is a parameter "client_max_body_size" inside the http{}. It has a default value of 1048m. Even if this seems big enough I have changed it to 2048m.
Unfortunately this didn't work and the result is still the same.
#2 EDIT
So I'm still having the problem.
As I commented below I'm using a form_remote_tag with a dynamically populated table inside. This will submit using XMLHttpRequest in the background instead of the regular reloading POST arrangement.
This generates:
<form action="/wizi_comm/stats" method="post" onsubmit="Element.hide('err');Element.show('spinner');; new Ajax.Request('/wizi_comm/stats', {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('spinner');Element.show('mainBd');}, parameters:Form.serialize(this)}); return false;">
I have also tested using form_tag and the result is the same. Some parameters are just not sent.
<form action="stats" method="post">
I have check passenger's config files with no luck. I do really need some ideas here:
Do you think this is due to a configuration somewhere?
Do you think I should change the way I'm submitting the form?
Thanks in advance for your help!
SOLUTION
I did some tests with Datatable's based solutions as rows().data(). I was still missing some rows. I was also getting some errors from the API.
At this point I think that other JS libraries on the project are interfering with jQuery. I will study this when I will have the time.
What I finally did is to remove Datatable's initialisation on the table and to use a pure CSS solution to do the scroll. If someone is interested, my solution is based on this:
Pure CSS solution scroll table
table.scroll {
width: 716px; /* 140px * 5 column + 16px scrollbar width */
border-spacing: 0;
border: 2px solid black;
}
table.scroll tbody,
table.scroll thead tr { display: block; }
table.scroll tbody {
height: 100px;
overflow-y: auto;
overflow-x: hidden;
}
table.scroll tbody td,
table.scroll thead th {
width: 140px;
border-right: 1px solid black;
}
table.scroll thead th:last-child {
width: 156px; /* 140px + 16px scrollbar width */
}
table.scroll thead tr th {
height: 30px;
line-height: 30px;
/*text-align: left;*/
}
table.scroll tbody { border-top: 2px solid black; }
table.scroll tbody td:last-child, thead th:last-child {
border-right: none !important;
}
Thanks again for your help !

ERROR chrome_views_delegate.cc(185) -- NOT IMPLEMENTED

Opportunity:
Hello, I have a situation that I simply can't figure-out. I am getting these errors from Dart when I run a quite simple example:
[13288:9212:0320/161303:ERROR:navigation_entry_screenshot_manager.cc(147)] Invalid entry with unique id: 3
[14080:11508:0320/155717:ERROR:chrome_views_delegate.cc(185)] NOT IMPLEMENTED
[14080:11508:0320/155717:ERROR:desktop_root_window_host_win.cc(753)] NOT IMPLEMENTED
[14080:11508:0320/155719:ERROR:desktop_root_window_host_win.cc(753)] NOT IMPLEMENTED
[14080:11508:0320/155747:ERROR:extension_icon_image.cc(201)] Start loading extension icon for Chromium. scale = 1
The messages don't really connect to the Use-Case I'm implementing. My attempts to use debug and other tools have come to not much indeed. I have 'reduced' the problem to a simple example based on the DartPolymer example:
Define a Custom Element tutorial.
This tutorial defines a DartPolymer component called <tut-stopwatch>. In my example I have copied that element as two clones: <x-fred> and <z-fred>. Everything is identical in a diff command, except the names and tags.
The layout of the main index.html page is as follows:
<body>
<x-fred> </x-fred>
<hr/>
<h1>Stopwatch</h1>
<tut-stopwatch> </tut-stopwatch>
<hr/>
<z-fred> </z-fred>
</body>
Investigation so far:
I put a break-point on the DOM register call and the stopwatch creator (constructor):
class TuteStopwatch extends PolymerElement {
#observable String counter='00:00';
TuteStopwatch.created() : super.created();
:
}
The "unique id message" as I call it comes up:
[13288:9212:0320/161303:ERROR:navigation_entry_screenshot_manager.cc(147)] Invalid entry with unique id: 3
During debugging. There's no clear connection to the code executing and I think that this is an async message, unrelated to the registration of the <tut-stopwatch> component.
The other two examples (different in name and a label only): <x-fred> and <z-fred> work fine. It is just the <tut-stopwatch> element that poses a problem.
This is difficult for two reasons:
I have a stand-alone <tut-stopwatch> example working fine.
Despite text and lexical code-compare of three bits of "congruent" code, one is flawed in a specific context. It speaks to a lack of robustness some place.
Obviously I need a bit of direction on where to look for the problem. It reminds me of those games: "One of these things is not like the other . . . "
Thanks in advance.
Code
<tut-stopwatch>
Based on: Define a Custom Element example:
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:html';
import 'dart:async';
import 'package:polymer/polymer.dart';
#CustomTag('tute-stopwatch')
class TuteStopwatch extends PolymerElement {
#observable String counter='00:00';
TuteStopwatch.created() : super.created();
Stopwatch mywatch = new Stopwatch();
Timer mytimer;
:
}
<x-fred>
#CustomTag('x-fred')
//#CustomTag('tute-stopwatch')
class XFred extends PolymerElement {
#observable String counter='00:00';
XFred.created() : super.created();
Stopwatch mywatch = new Stopwatch();
Timer mytimer;
Stopwatch mywatch = new Stopwatch();
Timer mytimer;
:
}
Note: each element is in a different sub-folder and there is no name space collision between on the TuteStopwatch{...} class with <x-fred> and <z-fred>
tut_stopwatch.html
This file is in its own folder with tute_stopwatch.dart:
elements/fred/tute_stopwatch.html
<template>
<style>
:host {
background-color: yellow;
text-align: center;
display: inline-block;
border: solid 1px;
padding: 10px 10px 10px 10px;
}
</style>
<div>
<div> stopwatch:
{{counter}}
</div>
<div>
<button on-click="{{start}}" id="startButton">Start</button>
<button on-click="{{stop}}" id="stopButton">Stop</button>
<button on-click="{{reset}}" id="resetButton">Reset</button>
</div>
</div>
</template>
<script type="application/dart" src="tute_stopwatch.dart"> </script>
fred.html (<x-fred>)
This file is in its own folder with Fred.dart:
elements/fred/fred.html
<template>
<style>
:host {
background-color: blue;
text-align: center;
display: inline-block;
border: solid 1px;
padding: 10px 10px 10px 10px;
}
</style>
<div>
<div> fred:
{{counter}}
</div>
<div>
<button on-click="{{start}}" id="startButton">Start</button>
<button on-click="{{stop}}" id="stopButton">Stop</button>
<button on-click="{{reset}}" id="resetButton">Reset</button>
</div>
</div>
</template>
<script type="application/dart" src="fred.dart"> </script>
github
I have put the failing case on GitHub here:
- https://github.com/aplatypus/dart-experiments
This version fails to show the tute-stopwatch element. Yet clones with a different name work OK. Same code, just different names.
work-around
I can report that I have a work-around. I'm more or less convinced that its a Dart or Dart Editor bug though.
The fix was to manually rename: <tute-stopwatch> to: <x-stopwatch>
The x-stopwatch version of the (same) code then worked a-OK. Then I renamed the custom element back again to:
<tute-stopwatch>
And now the: <tute-stopwatch> is working.
I don't think its a satisfying resolution because I pretty much purged the project folder and Packages cache a couple of times. There be something hanging about me thinks.
Also I'm still seeing odd errors:
F:\.bin\dev\dart\dev\chromium\Chrome.exe --remote-debugging-port=59082 --user-data-dir=C:\Users\william\.dartium --enable-experimental-web-platform-features --enable-html-imports --no-first-run --no-default-browser-check --no-process-singleton-dialog chrome://version/
[18040:16896:0322/210119:ERROR:chrome_views_delegate.cc(185)] NOT IMPLEMENTED
[18040:16896:0322/210119:ERROR:desktop_root_window_host_win.cc(753)] NOT IMPLEMENTED
[18040:16896:0322/210121:ERROR:desktop_root_window_host_win.cc(753)] NOT IMPLEMENTED
When I completely remove the tute-stopwatch element the messages go away, but I still see this:
[18040:16896:0322/210647:ERROR:navigation_entry_screenshot_manager.cc(147)] Invalid entry with unique id: 6
The number for 'unique id' changes from run to run of course.
I figured I'd post the outcome. If you have a similar situation try a different name for the element in question. That may help someone facing similar weirdness.

Asp.Net MVC 4 Generic Element

Sorry for the generic title, but i dont know how to call the element i want to create. Thats what i need... i tried to post image, but i dont get necessary privileges yet. So ill try to describe it.
Here on stackoverflow, on the question's page, after each title and summary there are some boxes displaying the tags from the questions.
I want the exactly same look, but instead of links, those boxes should act the same way as a Radio Button List. I can only choose one of then at a time and when pick one, the selected one ill get different style added to him. After submitting the form i should be able to recover de selected item in the controller.
I'm using Asp.Net MVC4 and the options that make the element will come from a controller.
Sorry for the question without code or something that i allready make. But i have this necessity and i dont even know if this sort of style or element have an specific name or keyword D.
Do you guys know from where to start with something (tutorials with similar final result ?) ?
Thanks for the help and sorry for the bad english.
Code After Looking at the proposed answers' link
CSS Code
input[type=radio] { display: none;}
.rbLista span { font-family: "Lucida Grande","Lucida Sans Unicode",Arial,Helvetica,Sans-serif;
font-size:12px; background: RGB(217,217,217); border: 1px solid RGB(217,217,217); }
.rbLista span:hover { border: 1px solid RGB(54,52,53); background: RGB(54,52,53); color: white; }
.rbLista input[type=radio]:checked + span { background: #D71712; color: #fff; border: 1px solid #D71712; }
.rbLista input[type=radio]:checked + span:hover { background: #D71712; }
and View Code
<section class="rbLista">
#foreach (var item in Model.ChamadoDetalhe.Transitos)
{
<label>
#Html.RadioButtonFor(x => x.NovoTransito.Transito, #item.Text, new { #id = item.Text, #text = item.Text })<span>#item.Text</span>
</label>
}
#Html.ValidationMessageFor(x => x.NovoTransito.Transito)
</section>
You could try something like this. Here's a working demo.

Asp.net MVC 3 RC - Razor ValidationMessageFor CustomMessage and ClientSideValidation Problem

ASP.Net MVC 3 RC, Razor
Experiencing some unexpected behavior when I try to use a custom message and using client side validation. The problem is it always displays the custom message even though there is no error.
So say I have a Client Model where the FirstName is set as Required. If I have the following code the validation message is not displayed until I click on Submit which works as expected.
#Html.EditorFor(model => model.Client.FirstName) #Html.ValidationMessageFor(model => model.Client.FirstName)
But now say I want to customize the validation message to use an asterisk like so:
#Html.EditorFor(model => model.Client.FirstName) #Html.ValidationMessageFor(model => model.Client.FirstName, "*")
Now even before I click on the submit button, there is always an asterisk next to the field.
The expected behavior is that it would show the asterisk when there is a validation error.
Thanks for any help.
I found the problem, the following CSS is needed:
.field-validation-valid
{
display: none;
}
.validation-summary-valid
{
display: none;
}
Somewhere along my refactoring those classes got taken out. They are in there by default when you start a new MVC 3 project. Hope that helps someone in the future!
The chosen answer didn't work for me. I had to use the following. Note the class is "error", not "valid". This hides the validation message being shown on page load.
<style>
.field-validation-error
{
display: none;
}
.validation-summary-valid
{
display: none;
}
</style>

Resources