Created
August 12, 2011 19:59
-
-
Save Shadow6363/1142865 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var historyCount = parseInt($('#historyCount').val()); | |
$('#AddMaintenance').click(function(event) { event.preventDefault(); | |
var firstMaintenance = parseInt($('#FreezerFirstMaintenance').val()); | |
$('#preventativeMaintenance').clone(false, false).html($('#preventativeMaintenance').html()).find(':input').each(function() { | |
$(this).attr('id', $(this).attr('id').replace(firstMaintenance, historyCount)); | |
$(this).attr('name', $(this).attr('name').replace('[' + firstMaintenance + ']', '[' + (historyCount) + ']')); | |
if($(this).is('[type!="hidden"]')) { $(this).val(''); } | |
}).end().insertBefore('#AddMaintenance'); historyCount++; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<fieldset style="border: none;"> | |
<legend id="preventativeMaintenanceLegend"> | |
<span class="ui-icon ui-icon-triangle-1-e" id="preventativeMaintenanceArrow" style="display: inline-block;"></span> | |
<span>Preventative Maintenance Information</span> | |
</legend> | |
<div id="preventativeMaintenances" style="display: none; margin-left: 2.5%;"> | |
<div id="preventativeMaintenance"> | |
<?php | |
/* THIS IS THE IMPORTANT PART: | |
You need a hidden field that keeps track of whatever your first hard-coded form is. | |
In the above JS, you need the var firstMaintenance = stuff to be named the same. | |
*/ | |
echo $this->Form->hidden('firstMaintenance', array('value' => 0)); | |
echo $this->Form->hidden('EquipmentHistory.0.subject', array('value' => '1')); | |
echo $this->Form->input('EquipmentHistory.0.date', array('empty' => true)); | |
echo $this->Form->input('EquipmentHistory.0.details'); | |
?> | |
</div> | |
<?php for($i = 4; $i < count($this->data['EquipmentHistory']); $i++): ?> | |
<?php if($this->data['EquipmentHistory'][$i]['subject'] == 1): ?> | |
<div id="preventativeMaintenance"> | |
<?php | |
echo $this->Form->hidden('EquipmentHistory.' . $i . '.subject', array('value' => '1')); | |
echo $this->Form->input('EquipmentHistory.' . $i . '.date', array('empty' => true)); | |
echo $this->Form->input('EquipmentHistory.' . $i . '.details'); | |
?> | |
</div> | |
<?php endif; ?> | |
<?php endfor; ?> | |
<button id="AddMaintenance">Add Preventative Maintenance Information</button> | |
</div> | |
</fieldset> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment