Skip to main content
added 264 characters in body
Source Link
Peter Lewis
  • 5.4k
  • 15
  • 22

Use CP CSS & JS to inject some JQuery.

Then target form#publishForm, something like this

if ($("form#publishForm #hold_field_19").val() == "") {
    $("form#publishForm #hold_field_19").hide();
}
$("form#publishForm #field_18").on('input', function() {
    if ($(this).val() != "") {
        $("form#publishForm #hold_field_19").fadeIn();
    }
}

Assumes field_18 is first name and field_19 is last name.

One problem you may need to add conditionals for in the JQuery is if the first name is empty, but last name is not - you don't want to hide the last name field. Also need to check if the first name is deleted during the editing, should the last name disappear at that point?

"then it requires less conditionals in the templates."

Not quite sure how that's going to change as you're still going to want to know if a field has a value to display it or not...?

Remember for different channels you can change the layout and what fields are shown hidden (albeit permanently and not relevant to other fields having a value).

Use CP CSS & JS to inject some JQuery.

Then target form#publishForm, something like this

if ($("form#publishForm #hold_field_19").val() == "") {
    $("form#publishForm #hold_field_19").hide();
}
$("form#publishForm #field_18").on('input', function() {
    if ($(this).val() != "") {
        $("form#publishForm #hold_field_19").fadeIn();
    }
}

Assumes field_18 is first name and field_19 is last name.

One problem you may need to add conditionals for in the JQuery is if the first name is empty, but last name is not - you don't want to hide the last name field. Also need to check if the first name is deleted during the editing, should the last name disappear at that point?

"then it requires less conditionals in the templates."

Not quite sure how that's going to change as you're still going to want to know if a field has a value to display it or not...?

Use CP CSS & JS to inject some JQuery.

Then target form#publishForm, something like this

if ($("form#publishForm #hold_field_19").val() == "") {
    $("form#publishForm #hold_field_19").hide();
}
$("form#publishForm #field_18").on('input', function() {
    if ($(this).val() != "") {
        $("form#publishForm #hold_field_19").fadeIn();
    }
}

Assumes field_18 is first name and field_19 is last name.

One problem you may need to add conditionals for in the JQuery is if the first name is empty, but last name is not - you don't want to hide the last name field. Also need to check if the first name is deleted during the editing, should the last name disappear at that point?

"then it requires less conditionals in the templates."

Not quite sure how that's going to change as you're still going to want to know if a field has a value to display it or not...?

Remember for different channels you can change the layout and what fields are shown hidden (albeit permanently and not relevant to other fields having a value).

Source Link
Peter Lewis
  • 5.4k
  • 15
  • 22

Use CP CSS & JS to inject some JQuery.

Then target form#publishForm, something like this

if ($("form#publishForm #hold_field_19").val() == "") {
    $("form#publishForm #hold_field_19").hide();
}
$("form#publishForm #field_18").on('input', function() {
    if ($(this).val() != "") {
        $("form#publishForm #hold_field_19").fadeIn();
    }
}

Assumes field_18 is first name and field_19 is last name.

One problem you may need to add conditionals for in the JQuery is if the first name is empty, but last name is not - you don't want to hide the last name field. Also need to check if the first name is deleted during the editing, should the last name disappear at that point?

"then it requires less conditionals in the templates."

Not quite sure how that's going to change as you're still going to want to know if a field has a value to display it or not...?