Randy,

You can use PHP to check if fields should be hidden at runtime and
Javascript to then update fields as the user interacts with the form.
So injecting <?php if($this->data['ModelName']['type'] == 1) echo "
style='display:none'"; ?> into your $this->Form-
>input('ModelName.asset') call would set the state on page load and
your Javascript function could then deal with any changes in state.

On a side note, you have made an excellent choice in using CakePHP as
your preferred PHP Framework, so why not also use a framework for
Javascript?  I prefer jQuery (previously used prototype, but found
jQuery is now a much bigger more updated project) and to do what you
want would simply be a matter of:

// if only two type values to choose from
$( document ).ready(function() {
  if( $( '#ModelNameType' ).val() != 1 ) {
    $( '#ModelNameAsset' ).hide(); // hide asset on page load
  }
  $( '#ModelNameType' ).change(function() {
    $( '#ModelNameAsset' ).toggle();
  });
});

// if more than two type values to choose from
$( document ).ready(function() {
  $( '#ModelNameType' ).change(function() {
    typeChange( this.val() );
  });
  function typeChange(val) {
    if( val == 1 ) {
      $( '#ModelNameAsset' ).show();
    } else {
      $( '#ModelNameAsset' ).hide();
    }
  }
});

Not tested the above, but it's fairly basic stuff so should work if no
typos :)

HTH, Paul.

On Aug 15, 8:51 pm, Randy <[email protected]> wrote:
> I'm trying to format input boxes based on the input data.
> In particular there is an asset field that is available (or not) based
> on a type field.
> If the type field is changed to one of several options the asset field
> display is turned on and off.
>
> I have it working using a small javascript function within the view,
> when an item type is changed.   But I want to use the same javascript
> to run when the view is loaded for default behavior.
>
> I tried the windows.onload, but this runs before the page is rendered,
> and crashes because the fields on the page have not been created yet.
>
> Anybody have an Idea how to accomplish this?
>
> Thanks

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to