You are viewing limited content. For full access, please sign in.

Question

Question

Side-by-Side Form Fields & Rules

asked on January 13, 2014

Has anyone else had problems when using the CSS code {display:inline-block} on fields that also have Field Rules in place?

 

Basically, I have two fields that are hidden unless a check box is checked. The Field Rule I had set works fine, but after altering the look of the form so that these two fields are side-by-side (using inline-block), the fields aren't hidden now but are read only (grey'd out) until the check box is checked rather than being hidden until checked. Any ways around this?

 

Many thanks!

Dom

0 0

Answer

APPROVED ANSWER
replied on January 13, 2014

When you specify a layout for fields, like in-line display, rules disable those fields instead of hiding them, because hiding them would change the layout. Take the following example, where there are three fields displayed side-by-side.

 

 

 

The second field is hidden by a field rule but appears disabled so the layout structure stays intact. Here's what it looks like when that field is hidden:

 

 

Another example of this is hiding fields within tables. If you completely hide a field in a table, it throws the table's layout off. In order to prevent that, the field is disabled instead of hidden. See the discussion in this question for more information and some solutions you can use.

 

 

 

 

 

1 0

Replies

replied on January 13, 2014 Show version history

You may need to have Javascript running on top of all of that custom work in order to control what is being seen.You can use javascript to add/change CSS if you use it properly. You could also just use Javascript to handle the same field rule you've created using the standard forms tools

 

I have not personally come across what you are saying but if I did, that would be my course of action.

 

It is quite understandable that this stuff might happen when using custom CSS and using Field Rules. The CSS may get a little screwy if something appears before the other (or is meant to work like that).

 

Good Luck and I look forward to hearing about how you handle this.

0 0
replied on January 13, 2014

Thanks for the ideas guys.

 

Just created & tested some JavaScript rules that mimicked the rules I was originally looking for. Would have worked fine if it weren't for the fact the fields I'm using are in a Collection! :(

 

I take it each field within a Collection can't have it's own rules? Will have to re-think the form...

 

Thanks again!

Dom

0 0
replied on January 13, 2014

You can use rules with fields in collections. Let me know what you're trying to do and maybe I can help sort out the issues you're experiencing.

0 0
replied on January 13, 2014 Show version history

you need to use a hyphen. Say the field is Field 32, then you refer to it in Javascript as '#Field32-0' or '#Field32-1' if you have it set to a specific amount of amount of items.

 

Now, if it's a collection with an unknown amount, try having your javascript like this:

 

$('[id^=Field32]').each(function(){
        //Code here
    });
    

 

0 0
replied on January 22, 2014

Hi Kenneth,

 

Thanks for the input but I'm having no luck when using a hyphen to determine which field to copy data from. I have set my collection to have max = 10 groups of fields. When using what you said in the following it doesn't bring back any value:

$('#q74 input').val($('#q50-1 input').val());

Any ideas?

 

Many thanks,

Dom

0 0
replied on January 22, 2014 Show version history

If you're targeting a specific repeated field, use the following structure:

$('#q50(1) input').val();

If you want to find that value for each repeated collection of fields, you'll want to approach things differently. Here's an example:

 

$('.cf-collection-block ul').each(function () {
    var mySum = $(this).find('.sum input');
});

Basically, you'll target each block of repeated fields, and find the specified field using a CSS class you added to it. In this case, I added the sum class. I'd recommend this approach instead of trying to use field identifiers.

 

Does that make sense? You can see this in action in the Calculating the subtotal of fields within a repeatable collection section on this page of the help.

0 0
replied on January 23, 2014

Hi Eric,

 

Thanks again for the comments - really appreciate it! Sorry for the late replies.

 

The top example didn't work for what I wanted but I will try the second example now. I imagine that I can create some sort of variable array from the values I'm returning for "mySum", is that correct?

 

Thanks again for the help - clearly JavaScript is not my best area...

0 0
replied on January 13, 2014

I have a collection with the following:

 

  • One set of check boxes (ID =#q57, CSS Class=OptionsCheck)
    • Has a number of options, the first being "ADF" (Value=ADF)

 

  • Two fields that associate with each checkbox. For example,
    • "ADF Model" & "ADF Serial" (Both these belong to a CSS Class = ADF)

 

What I was hoping to do was have the form show the two fields once the check box was clicked, which I managed. The only problem I had was that it would show the two fields in every collection set once I selected the matching check box value. 

 

I had purposely put the two fields in a CSS class named ADF that matches the value from the checkbox because I had hoped to retrieve the value of the check box that was selected and use the value from that (which in this case would be ADF) as some sort of identifier to use in my show()/hide() statement.... I ended up writing out a tonne of IF/ELSE statements in the end...

 

Would this hyphen(Amount) work on CSS classes? Or would I have to specify it on each ID of the field?

 

Thanks for helping out & I apologise if I make little sense!

0 0
replied on January 13, 2014

Basically, your JavaScript needs to target each of the repeatable collections that can appear. Here's some code that should work with the classes you specified.

 

$(document).ready(function () {
    $('.cf-collection-block').on('change', showhide);

    function showhide() {
        $('.cf-collection-block ul').each(function () {

            if ($(this).find('.OptionsCheck input:checked').val() == 'ADF') {
                $(this).find('.ADF').hide();
            }
            else {
                $(this).find('.ADF').show();
            }
        });

    }
});

So, instead of finding all of the ADF fields and hiding them, we're only finding the ones in the appropriate repeated collection of fields.
 

1 0
replied on January 14, 2014 Show version history

Hi Eric, this works great for what I was after! - I just need to swap the show/hides as I wanted it to display the field when the checkbox is checked.

 

This leads me to another question now though (I'm sorry)! I wanted to use field rules as you know to show the fields when the boxes were ticked, therefore I was hoping to keep the fields hidden in the collections on page load. Even though I have used the following:

 

  $(".ADF").hide();

 

at the start of my JavaScript, the fields in added collections are still visible to start with. Is there a bit of code I need to add to tell it to apply for all?

 

Also, the code posted works only for one checkbox to display it's field - could this work for multiple? 

Let's say I had check box ADF and FAX, both having 2 fields each. Is it possible to write JavaScript so that if I also wanted to display the FAX fields when checked I could do?

0 0
replied on January 14, 2014

Also, the code posted works only for one checkbox to display it's field - could this work for multiple? 

Let's say I had check box ADF and FAX, both having 2 fields each. Is it possible to write JavaScript so that if I also wanted to display the FAX fields when checked I could do?

replied on January 14, 2014

If you want to have the fields hidden at the beginning, you'll want to use CSS to hide the fields initially. Try the following CSS rule:

.ADF {display:none;}

As for your second question, you could copy the code above and change OptionsCheck and ADF to the relevant classes and it should work.

0 0
replied on January 14, 2014

Hi Eric,

 

I managed to get the other check boxes doing what I had initially planned doing something similar to what you mentioned.

 

I'm unable to use {display:none;} because the fields are side-by-side - using the {display:inline-block;}. Things just get trickier and trickier! indecision I will continue to investigate possible options, thanks for all the help!

0 0
replied on January 14, 2014

If you want the field to be hidden but the layout to stay the same, instead of hiding the field container (#q3, for example), you can hide the stuff inside it (the label and the input box)

 

Try this:

 

.ADF input {display:none;}
.ADF .cf-label {display:none;}

 

2 0
replied on January 28, 2014

Eric,

 

If our forms has multiple fields formatted using CSS and visible based on checkboxes values of different fields, would it make since to use the CSS above to hide the fields and include a javascript to check every field and make them invisible if it's disabled. I would assume that would be easier to maintain in the long run. 

0 0
replied on January 30, 2014

I might not understand your exact use-case, but ff you want to hide the fields when the form loads, hiding them with CSS is the way to go. Then, you can use JavaScript to show them when certain actions happen on the form.

0 0
replied on April 16, 2014

Hi all,

 

I had the same problem.

I just replaced the CSS part:
#ID1, #ID2 {display: inline-block;}

by:
#ID1, #ID2 {position: relative; float: left;}

and my problem was solved.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.