Level 48
Hi
You could do something like this (not tested).
- Create a file input file with id 'file_input'
- Create a text field with id 'text_input'
Hide both field if the form is loaded.
#text_input, #file_input { display: none; }
If select is changed.
<script type="text/javascript">
document.getElementsByClassName('select2').addEventListener("change", function() {
if (this.options[this.selectedIndex].value == 'image') {
// Show file input.
document.getElementById('file_input').style.display = 'block';
// Hide and clear text input
document.getElementById('text_input').value = '';
document.getElementById('text_input').style.display = 'none';
}
else {
// Hide and clear file field.
document.getElementById('file_input').style.display = 'none';
document.getElementById('file_input').value = '';
// Show text input field
document.getElementById('text_input').style.display = 'block';
}
});
</script>
Other option is doing a ajax request and load the fields in the onchange function.
Also remember if you want to use the file input, you need to add 'files'=>'true' to your form.
Form::open(array('url' => '/form-submit-page', 'files'=>'true'));