Lamians/ZF3: Adding CSS Class to invalid Form Fields - zend-framework

I would like to add an Red Border - for example through adding an CSS Class - to invalid input fields. What is the best way to do so ?
Or does Laminas already have something built in for this ?
kind regards
Jan

Laminas doesn't actually handle CSS, since this is frontend stuff.
Keep in mind that both solutions requires to send the post request to your server
Solution 1
Inside your view, you can check if an element has error messages, and add an additional class:
<?php $description = $this->form->get('description'); ?>
<div class="form-group row<?= $this->formElementErrors($description) ? ' has-error' : ''; ?>">
<?= $this->formLabel($description); ?>
<div class="col-sm-10">
<?= $this->formElement($description); ?>
<span class="error-message">
<?= $this->formElementErrors($description); ?>
</span>
</div>
</div>
In this exemple, when an element has error messages (therefore, the input is invalid), it adds the class has-error to it. This class comes from Bootstrap, and the CSS style is:
.has-error .help-block,
.has-error .control-label,
.has-error .radio,
.has-error .checkbox,
.has-error .radio-inline,
.has-error .checkbox-inline,
.has-error.radio label,
.has-error.checkbox label,
.has-error.radio-inline label,
.has-error.checkbox-inline label {
color: #a94442;
}
.has-error .form-control {
border-color: #a94442;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
}
.has-error .form-control:focus {
border-color: #843534;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #ce8483;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 6px #ce8483;
}
.has-error .input-group-addon {
color: #a94442;
background-color: #f2dede;
border-color: #a94442;
}
.has-error .form-control-feedback {
color: #a94442;
}
Solution 2
Take a look at Laminas FormElementErrors helper

Related

Can't find what is adding width to a form element

I have a search box that expands upon hover which relies on the input field being completely hidden initially; however I can't seem to find what is causing this width.
Here is my code; and the live version is: http://stylrs.com/ctf/
.search_header {
float: right;
clear: both;
height: 30px;
}
.search_header input {
-moz-transition: width 0.5s;
-ms-transition: width 0.5s;
-webkit-transition: width 0.5s;
transition: width 0.5s;
width: 0;
margin: 0 !important;
}
.search_header input:focus,
.search_header:hover input {
width: 135px;
}
.fa-input {
background-color: none !important;
color: white;
float: right;
font-family: FontAwesome, 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 15px;
margin-top: 1px;
width: 15px !important;
border: none !important;
padding: 0;
margin: 0;
}
.search_header input[type="text"] {
margin-right: 0;
font-size: 12px;
}
.search_header input[type="submit"] {
appearance: value;
background: none !important;
webkit-appearance: none !important;
}
<div class="search_header">
<form role="search" method="get" id="searchform" class="searchform" action="test">
<div>
<label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label', 'QEPRize'); ?></label>
<input type="text" value="test" name="s" id="s" />
<input type="submit" class="btn fa-input" value="">
</div>
</form>
</div>
It’s padding and border what causes the input to be visible (even when the width is zero).
Set these properties to zero as well and make them part of your animation.

CSS3 custom checkbox - cross-browser differences

I've recently been working on some custom checkboxes for a while now and have found it to be a challenge. However, I'm so close to finishing them and had been testing a lot in Chrome which I managed to get them perfect.
I then checked in the other browsers and there were some distinct differences in how my after state was rendered. How do you fix those differences? is it even possible? Or do I just have to use an image?
JSFIDDLE
HTML:
<div class="fb-checkbox">
<br>
<br>
<input id="item21_0_checkbox" name="Project_type[]" type="checkbox" data-hint="" value="Conference" /><label for="item21_0_checkbox" id="item21_0_label" ><span id="item21_0_span" class="fb-fieldlabel">Conference</span></label>
<input id="item21_1_checkbox" name="Project_type[]" type="checkbox" value="Incentive campaign" /><label for="item21_1_checkbox" id="item21_1_label" ><span id="item21_1_span" class="fb-fieldlabel">Incentive campaign</span></label>
<input id="item21_2_checkbox" name="Project_type[]" type="checkbox" value="Incentive travel" /><label for="item21_2_checkbox" id="item21_2_label" ><span id="item21_2_span" class="fb-fieldlabel">Incentive travel</span></label>
<input id="item21_3_checkbox" name="Project_type[]" type="checkbox" value="Awards dinner" /><label for="item21_3_checkbox" id="item21_3_label" ><span id="item21_3_span" class="fb-fieldlabel">Awards dinner</span></label>
<input id="item21_4_checkbox" name="Project_type[]" type="checkbox" value="Product launch" /><label for="item21_4_checkbox" id="item21_4_label" ><span id="item21_4_span" class="fb-fieldlabel">Product launch</span></label>
<input id="item21_5_checkbox" name="Project_type[]" type="checkbox" value="Hospitality" /><label for="item21_5_checkbox" id="item21_5_label" ><span id="item21_5_span" class="fb-fieldlabel">Hospitality</span></label>
<input id="item21_6_checkbox" name="Project_type[]" type="checkbox" value="Comms and marketing" /><label for="item21_6_checkbox" id="item21_6_label" ><span id="item21_6_span" class="fb-fieldlabel">Comms and marketing</span></label>
<input id="item21_7_checkbox" name="Project_type[]" type="checkbox" value="Reward & Recoginition scheme" /><label for="item21_7_checkbox" id="item21_7_label" ><span id="item21_7_span" class="fb-fieldlabel">Reward & Recoginition scheme</span></label>
<input id="item21_8_checkbox" name="Project_type[]" type="checkbox" value="Design brief" /><label for="item21_8_checkbox" id="item21_8_label"><span id="item21_8_span" class="fb-fieldlabel">Design brief</span></label>
</div>
CSS:
input[type="checkbox"] {
display: none!important;
}
/*------ 1st checkboxes ----*/
input[type="checkbox"]:not(:checked) + label span,
input[type="checkbox"]:checked + label span {
position: relative;
cursor: pointer;
}
input[type="checkbox"]:not(:checked) + label span:before,
input[type="checkbox"]:checked + label span:before {
content: '';
position: absolute;
right: 10px;
width: 15px; height: 15px;
border: 1px solid #a5a5b1;
background: none;
border-radius: 3px;
-webkit-box-shadow: inset 0px 0px 8px 0px rgba(50, 50, 50, 0.13);
-moz-box-shadow: inset 0px 0px 8px 0px rgba(50, 50, 50, 0.13);
box-shadow: inset 0px 0px 8px 0px rgba(50, 50, 50, 0.13);
margin: 0;
padding: 0;
}
input[type="checkbox"]:not(:checked) + label span:after,
input[type="checkbox"]:checked + label span:after {
content: '★';
position: absolute;
width: 15px; height: 15px;
top: -1px;
right: 10px;
font-size: 1.2em;
border-radius: 3px;
color: #ffc20e;
transition: all .5s;
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
border: 1px solid #000000;
text-align: center;
vertical-align: middle;
}
input[type="checkbox"]:not(:checked) + label span:after {
opacity: 0;
transform: scale(0);
}
input[type="checkbox"]:checked + label span:after {
opacity: 1;
transform: scale(1);
}
input[type="checkbox"]:disabled:not(:checked) + label span:before,
input[type="checkbox"]:disabled:checked + label span:before {
box-shadow: none;
border-color: #bbb;
background-color: #ddd;
}
input[type="checkbox"]:disabled:checked + label span:after {
color: #999;
}
input[type="checkbox"]:disabled + label span {
color: #aaa;
}
/* accessibility */
input[type="checkbox"]:checked:focus + label span:before,
input[type="checkbox"]:not(:checked):focus + label span:before {
border: 1px dotted blue;
}
If you click the boxes for their checked state and in different browsers you'll notice positioning is off and even the size of the star is slightly different...
EDIT: I know my example doesn't show them perfectly align to start off with - just interested in why they're positioned differently
Try adding a line-height corresponding to the element height for your :after elements used to display the star,
input[type="checkbox"]:not(:checked) + label span:after,
input[type="checkbox"]:checked + label span:after {
/* … */
top: 0; /* modified */
line-height: 13px;
}
With that, it looks OK to me in Firefox and Opera. http://jsfiddle.net/mBWm3/1/

Multiple jQuery Pop-up Forms: Connect a href to <form> divs for user input

I'm working on a digital textbook feature that would allow the student to click a link to open up a simple div form for them to input their answer to that specific question. The pop-up form is just simple HTML/CSS with some jQuery UI to hide, show, and make it draggable. Here's the twist. I've got multiple questions that each need to be attached to a unique div. No problem, I thought. I'll just set each a href to link back to a unique ID that I've assigned within the DIV. Problem is, I can't seem to target the proper DIV with its corresponding a href. Instead the same set of questions appear no matter which link is clicked. This seems super simple and I'm probably overcomplicating it. What can I do here?
HTML:
<div id="draggable" class="messagepop pop">
<form method="post" id="new_message" action="/answers">
<p><label for="body">What type of person is Carsten?</label><textarea rows="15" name="body" id="body" cols="55"></textarea></p>
<p><label for="body">How do you know?</label><textarea rows="15" name="body" id="body" cols="55"></textarea></p>
<p><center><input type="submit" value="Submit" name="commit" id="message_submit"/> or <a id="hide" href="#">Cancel</a></center></p>
</form>
</div>
<div id="draggable" class="messagepop pop">
<form method="post" id="new_message" action="/answers">
<p><label for="body">What can you learn about an active volcano from the photograph?</label><textarea rows="15" name="body" id="body" cols="55"></textarea></p>
<p><center><input type="submit" value="Submit" name="commit" id="message_submit"/> or <a id="hide" href="#">Cancel</a></center></p>
</form>
</div>
Draw Conclusions What kind of person is Carsten? How do you know?
Use Text Features What can you learn about an active volcano from the photograph?
Where the first a href needs to open the first div and the second a href opens the second div, etc., etc.
CSS:
.messagepop {
overflow-y: auto;
overflow-x: hidden;
cursor:default;
display:none;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
text-align:left;
width:394px;
height: 335px;
z-index:50;
padding: 25px 25px 20px;
background-color: #fff;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
-moz-border-radius: 4px 4px 4px 4px;
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
-webkit-border-radius: 4px 4px 4px 4px;
border-color: #E5E5E5 #DBDBDB #D2D2D2;
border-style: solid;
border-width: 1px;}
JS:
$(document).ready(function() {
$('.show').click(function() {
if ( !$(this).next('div').is(':visible') ) {
$(".messagepop").slideFadeToggle();
$(this).next('div').slideFadeToggle();
}
});
$('.hide').click(function() {
$(this).parent().slideFadeToggle();});
$.fn.slideFadeToggle = function(easing, callback) {
return this.animate({ opacity: 'toggle', height: 'toggle' }, "fast", easing, callback);};
$(function() {
$("#draggable").draggable();});
Thank you for your advice and for ironing out my poorly written method. It seems you've got it working.
I've since discovered a jQuery Mobile solution that is much easier than what I was trying to pull together.
For future viewers, it would simply look like this.
Draw Conclusions
Use Text Features
<div data-role="popup" id="popup1" class="ui-content" data-position-to="window">
Close
<p>What kind of person is Carsten?</p>
<input type="text"/>
<p>How do you know?</p>
<textarea></textarea>
</div>
<div data-role="popup" id="popup2" class="ui-content" data-position-to="window">
Close
<p>What can you learn about an active <mark><b>volcano</b></mark> from the photograph?</p>
<textarea></textarea>
</div>
The logic here makes a lot more sense to me and there's the added benefit of ensuring it will work properly on mobile devices. Then if you want to make it draggable, just drop in:
<script>
$(function() {
$(".ui-content").draggable();
});
</script>
And then if you want it to be draggable on mobile (remember, jQuery UI isn't natively supported on mobile), you'll have to call up a hack of sorts. I like Touch Punch.
You may run into issues with form inputs when using Draggable combined with Touch Punch, but that's a story for another thread.
Here is a demo: http://jsfiddle.net/ebNsz/
I've set id:s for the question-div:s and target them with the 'href' attribute in the 'a' elements. Not sure what you wanted to do with the 'slideFadeToggle' function, so i used 'fadeToggle' instead.
HTML:
<div id="q1" class="messagepop">
<form method="" id="form1" action="/answers">
<label for="answer1">What type of person is Carsten?</label><textarea name="answer1" class="answer"></textarea>
<label for="answer2">How do you know?</label><textarea name="answer2" class="answer"></textarea>
<div>
<input type="submit" value="Submit" name="submit" /> or <a class="close" href="">Cancel</a>
</div>
</form>
</div>
<div id="q2" class="messagepop">
<form method="" id="form2" action="/answers">
<label for="answer1">What can you learn about an active volcano from the photograph?</label><textarea name="answer1" class="answer"></textarea>
<div>
<input type="submit" value="Submit" name="submit" /> or <a class="close" href="">Cancel</a>
</div>
</form>
</div>
<p>Draw Conclusions What kind of person is Carsten? How do you know?</p>
<p>Use Text Features What can you learn about an active volcano from the photograph?</p>
jQuery: (jsFiddle doesn't support .draggable(), so i commented out the first line and added the second.)
$(function() {
/* $("div.messagepop").draggable().hide();*/
$("div.messagepop").hide();
$("a.toggle").click(function(e)
{
e.preventDefault();
var targetpop = $(this).attr('href');
$(targetpop).siblings("div.messagepop").fadeOut();
$(targetpop).fadeToggle();
});
$("a.close").click(function(e)
{
e.preventDefault();
$(this).closest("div.messagepop").fadeToggle();
});
});
CSS:
.messagepop {
position: absolute;
top: 20%;
left: 50%;
z-index: 50;
margin-left: -197px;
text-align: center;
width: 394px;
height: 335px;
padding: 25px 25px 20px;
background-color: #fff;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
border-color: #E5E5E5 #DBDBDB #D2D2D2;
border-style: solid;
border-width: 1px;
}
label {
display: block;
}
textarea {
width: 75%;
height: 5em;
margin: 0 0 1em 0;
}

Column with div style and div id

For some reason I cannot get the text in my middle column (of three columns) to respond to any classes or styles I apply to it. I'm just trying to slide the text in the middle column over to the right a little bit.
CSS (stylesheet):
#footer-address {
font-size:20px;
padding-left:20px;
}
#nav-foot{
border:1px solid #ccc;
border-width:1px 0;
list-style:none;
margin:0;
padding:0px;
text-align:left;
font-size:12px;
}
#nav-foot li{
display:inline;
}
#nav-foot a{
display:inline-block;
padding:20px 0 20px 0;
}
#nav-social {
border:1px solid #ccc;
border-width:1px 0;
display:inline;
list-style:none;
margin:0;
padding:0px;
float: left;
}
#nav-social li{
display:inline;
}
#nav-social a{
display:inline-block;
padding:20px 0 20px 0;
}
HTML:
<div style="width:30%; float:left; margin: 10px 0 10px 0; position:relative;">
<ul id="nav-foot">
<li>About Us</li>
<li>Jobs</li>
<li>Contact Us</li>
</ul>
</div>
<div id="footer-address" style="width:30%; float:left; margin: 10px 20px 10px 20px; position:relative;">
375 6th St. </br>
Atlanta, GA 30308 </br>
Phone: 404-981-3934 </br>
Email: admin#perimetermaids.com
</div>
<div style="width:30%; float:left; margin: 10px 0 10px 0; position:relative;">
<ul id="nav-social">
</i>
<li></i></li>
<li></i></li>
<li></i></li>
<li></i></li>
</ul>
</div>
Sorry if the code is sloppy or the formatting of my question, however, I'm really scratching my head as to why this won't work.
My URL is http://perimetermaids.com/test if anybody needs that as well. This is for the black footer area. Thanks for the help, and hope you all have an awesome weekend!

how to display the sold out percentage in magento

I want to display the sold out percentage of product in magento.
For a example I am having 10 watches of a brand, in that two are sold out,
In that I product I want to sold out percentage like 20% and the bar which is indicating the sold out percetage.
Please help me out.
Regards
MD.Samiuddin
Hi Do you mean something like this?
PHP:
<?php
$initialAmount = 10;
$itemsLeft = Mage::getModel('cataloginventory/stock_item')
->loadByProduct($_product)->getQty();
$sold = $initialAmount - $itemsLeft;
$perc = $sold/$initialAmount*100;
?>
CSS
<style>
.bar {
height: 20px;
width:100%;
border: 1px solid #000000;
background-color: green;
}
.fill {
height: 20px;
width: <?php echo $perc; ?>%;
background-color: #FF0000;
font-size: 12px;
text-align: right;
line-height: 20px;
vertical-align: middle;
}
</style>
HTML
<div class='bar'>
<div class="fill"> <?php echo $perc; ?>%</div>
</div>
Check
Example