css - Changing the default popover look in ASP.NET MVC 4 Bootstrap using Razor or Jquery -


hi in advance. have registry form has on 15 fields. right i'm using data annotations validation , it's working well. need find way display edited popover when user mousses on form know fields required. right form has completed , if don't fill out required field user gets prompt @ submit time. turning out none functional , bad design strategy. have popover testing on 1 field. here might imagine lot of code fields display message this. want have bigger popover on input form display if user mouses on field. adress line 2 required field. , important need popover bigger different color , show on right off input box fields. here css code styles

<style> /* tooltip */  .tooltip > .tooltip-inner {     background-color: #73ad21;     color: #ffffff;     border: 1px solid green;     padding: 15px;     font-size: 20px; } /* tooltip on top */  .tooltip.top > .tooltip-arrow {     border-top: 5px solid green; } /* tooltip on bottom */  .tooltip.bottom > .tooltip-arrow {     border-bottom: 5px solid blue; } /* tooltip on left */  .tooltip.left > .tooltip-arrow {     border-left: 5px solid red; } /* tooltip on right */ .tooltip.right > .tooltip-arrow {     border-right: 5px solid black; } 

                @html.labelfor(model => model.address2, htmlattributes: new    {        @class = "control-label col-md-2",        data_toogle = "popover",        data_trigger = "hover",        data_container = "body",        data_placement = "right",        title = "address2 not mandatory"    })` 

the beauty of solution work required fields, , extension method, don't have specify different tooltip foreach field. make sure add jquery , jquery-ui. add extension method. use specified namespace:

namespace system.web.mvc.html {     public static class helpers     {         public static mvchtmlstring labelwithtooltip<tmodel,             tvalue>(this htmlhelper<tmodel> helper, expression<func<tmodel, tvalue>> expression)         {             var metadata = modelmetadata.fromlambdaexpression(expression, helper.viewdata);             string htmlfieldname = expressionhelper.getexpressiontext(expression);             string labeltext = metadata.displayname ?? metadata.propertyname ?? htmlfieldname.split('.').last();             if (string.isnullorempty(labeltext))                 return mvchtmlstring.empty;             var label = new tagbuilder("label");             label.attributes.add("for", helper.viewcontext.viewdata.templateinfo.getfullhtmlfieldid(htmlfieldname));             //credit method goes https://silverhair2010.wordpress.com/2012/10/10/creating-tooltips-using-data-annotations-in-asp-net-mvc/             //i modified next line             //if (!string.isnullorempty(metadata.description))             if (metadata.isrequired)                 label.attributes.add("title", htmlfieldname + " required.");              label.setinnertext(labeltext);             return mvchtmlstring.create(label.tostring());         }     } } 

use controller , model:

public class somodel {     [required]     public string name { get; set; }      [required]     public string address1 { get; set; } }  public class homecontroller : controller {     public actionresult ppindex()     {         return view(new somodel());     } 

this view:

@{     layout = null; } @model testy2.controllers.somodel <!doctype html> <html lang="en"> <head>     <meta charset="utf-8">     <meta name="viewport" content="width=device-width, initial-scale=1">     <title>jquery ui tooltip - default functionality</title>     <link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">     <link rel="stylesheet" href="/resources/demos/style.css">     <script src="https://code.jquery.com/jquery-1.12.4.js"></script>     <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>     <script>         $(function () {             $(document).tooltip();         });  </script>  <style>         label          {             display: inline-block;             width: 5em;         }      /*i got styling ideas http://stackoverflow.com/questions/4780759/overriding-css-styles-of-the-jquery-ui-tooltip-widget*/       .ui-tooltip {          display: none;          background: black;          font-size: 12px;          height: 10px;          padding: 10px;          color: #fff;          z-index: 99;          bottom: 10px;          border: 2px solid white;          /* ie */          filter: alpha(opacity=80);          /* css3 standard */          opacity: 0.8;      }     </style> </head> <body>     @html.labelwithtooltip(model => model.address1) </body> </html> 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -