Created
January 24, 2016 17:07
-
-
Save cesjam7/d250ea67609bf8a8907e 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
<div class="panel panel-primary"> | |
<script> | |
$(document).ready(function() { | |
var max_fields = 10; //maximum input boxes allowed | |
var wrapper = $("#datos_extras"); //Fields wrapper | |
var add_button = $(".agregar_datos"); //Add button ID | |
<?php $datos = get_post_meta(get_the_id(), "datos_extras", true); | |
if($datos==null) $datos = 0; ?> | |
var x = <?php echo $datos ; ?>; | |
$(add_button).click(function(e){ //on add input button click | |
e.preventDefault(); | |
if(x < max_fields){ //max input box allowed | |
$(wrapper).append('<div class="datos_extras"><div><input type="text" class="form-control" name="datos_extras_'+x+'_campo"></div><div><input type="text" class="form-control" name="datos_extras_'+x+'_valor"></div></div>'); //add input box | |
x++; //text box increment | |
$("#total_datos").attr("value", x); | |
} | |
}); | |
}); | |
</script> | |
<div class="panel-heading">Datos extras</div> | |
<div class="panel-body"> | |
<div class="form-group datos_extra"> | |
<label class="control-label">Datos extras:</label> | |
<?php if($edit){ ?> | |
<button class="agregar_datos">Agregar dato</button> | |
<?php | |
} ?> | |
<div class="datos_extras"> | |
<div>Campo</div> | |
<div>Valor</div> | |
</div> | |
<div id="datos_extras"> | |
<?php $c=0; | |
for ($i=0; $i < $datos; $i++) { ?> | |
<div class="datos_extras"> | |
<div><input type="text" class="form-control" name="datos_extras_<?php echo $c; ?>_campo" value="<?php echo get_post_meta(get_the_id(), "datos_extras_".$i."_campo", true); ?>" <?php if(!$edit) echo 'disabled'; ?>></div> | |
<div><input type="text" class="form-control" name="datos_extras_<?php echo $c; ?>_valor" value="<?php echo get_post_meta(get_the_id(), "datos_extras_".$i."_valor", true); ?>" <?php if(!$edit) echo 'disabled'; ?>></div> | |
</div> | |
<?php $c++; | |
} ?> | |
</div> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment