Solved

Could you point how to make a control initially not visible to be presented since it has a value?

Posted on 2016-10-07
6
71 Views
Last Modified: 2016-10-10
Hi Experts

Could you point how to make a control initially not visible to be presented since it has a value?

 <div class="col-xs-4 mb20 custo" style="display: none;">
	<label for="custo" class="field-label text-muted mb10">Custo</label>
	<div class="input-group">
		<span class="input-group-addon">
			<i class="fa fa-money c-gray"></i>
		</span>
		<span class="validar">
			<input type="text" name="custo" class="custo form-control gui-input br-light light" placeholder="">
		</span>
	</div>
</div>
</div>

Open in new window


Then in jQuery - the value isn't presented.
if ($('.custo').val()) $('.custo').show();   

Open in new window


Any workaround?

Thanks in advance.
0
Comment
Question by:Eduardo Fuerte
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 41833681
if ($('.custo').val() == '') $('.custo').show();

Open in new window

BUT
Be careful because your selector is a class. If you have two controls with class .custo then the above will check the first one - and if it is blank will show all of them
Consider these two examples
HTML 1
  <input type="text" class="test" style="display: none" value="3" />
  <input type="text" class="test" style="display: none" />

Open in new window

HTML 2
  <input type="text" class="test2" style="display: none" />
  <input type="text" class="test2" style="display: none" value="3" />

Open in new window

jQuery
$(function() {
  if ($('.test').val() == '') $('.test').show();
  if ($('.test2').val() == '') $('.test2').show();
});

Open in new window

In the first both will be hidden.
In the second both will be visible.
Working sample here
0
 

Author Comment

by:Eduardo Fuerte
ID: 41834276
Hi

I use the textbox as a class in 02 modals - since the values will be the same, no matter.

Accordingly to:
img001

 if ($('#edit. custo').val() != '0')
         {
            $('#edit .custo').show();
         }
    else 
    {
        $('#edit .custo').hide(); 
    }

Open in new window

0
 

Author Comment

by:Eduardo Fuerte
ID: 41836769
Hi Julian

After a better read on you example.
Just one thing that confused me a little.

The value must be presented if it has a value and doesn't if it hasn't a value.

So the comprehension must to be inverted.
0
Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

 
LVL 57

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41836834
Then == becomes != and the example output switches around but the principle is the same.

Here is the same sample with the logic inverted - does this make more sense?
0
 

Author Closing Comment

by:Eduardo Fuerte
ID: 41836855
Perfect explained.

Thank you for assistance!
0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 41836990
You are welcome.
0

Featured Post

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question