edit.ctp 2.52 KB

<div class="formules form">
    <?= $this->Form->create($formule) ?>
    <fieldset>
		<h2>
			<i class="icon-plus"></i> Ajouter une formule
		</h2>
      
	  
	  <?php
echo $this->Form->control('nommesure', [
    'label' => 'Nom mesure',
    'required' => 'required'
]);

echo $this->Form->control('symbole', [
    'label' => 'Symbole'
]);

echo $this->Form->control('unite', [
    'label' => 'Unité',
    'required' => 'required'
]);

echo $this->Form->control('nbVariable', [
    'label' => 'Nombre de variable(5 max.)',
    'default' => 1,
    'empty' => 1,
    'required' => 'required'
]);
?>
	  <div id="variable" style="display: none" required></div>
		<div id="derive" style="display: none" required></div>

	</fieldset>
    <?= $this->Form->submit(__('Valider')) ?>
    <?= $this->Form->end() ?>
</div>

<div class="actions">
	<?php
echo $this->element('menu');
echo $this->element('menu_form', [
    'pluralHumanName' => 'Formules'
]);
?>
</div>

<script type="text/javascript">



$(document).ready(function () {
		variable();
		$("#nbvariable").bind("focusout", function (event) {
				variable();
				});
			});
			
function variable(){
			var nbVariable = $("#nbvariable").val();
			
			if(nbVariable >=1 && nbVariable<=5){
			$("#variable").show();
			$("#derive").show();
			document.getElementById("derive").innerHTML="";
			document.getElementById("variable").innerHTML ="<table><tr><td> Variables </td><td>Symbole grandeur physique</td><td>Symbole unite mesure</td><td>nom Grandeur physique</td><td>Domaine de definition</td></tr></table>";
			for(var i=1;i<=nbVariable;i++){
			document.getElementById("variable").innerHTML +="<table><tr><td><label>X"+i+"</label></td><td><input type=\"control\" name=\"variables["+i+"][symbolegrandeurphysique]\" required></td><td><input type=\"control\" name=\"variables["+i+"][symboleunitemesure]\" required></td><td><input type=\"control\" name=\"variables["+i+"][nomgrandeurphysique]\" required></td><td><input type=\"control\" name=\"variables["+i+"][domainedef]\" placeholder=\"ex:[X;X[\" required></td></tr></table>";
			document.getElementById("derive").innerHTML += "<div class=\"input text required\"><label>Ecrire la dérivé partielle de F par rapport a la variable X"+i+"</label><input type=\"control\" name=\"variables["+i+"][derivepartielle]\" required></div>";
			}
			document.getElementById("derive").innerHTML += "<div class=\"input text required\"><label>Formule</label><input type=\"text\" name=\"formule\" id=\"formule\" required></div>";
			}else{
			alert("erreur");
			
			
			}
				
		}

	

</script>