9
Update: Just for the record, there is no need to use jQuery-ui, it can be with another solution.
I’m creating a autocomplete
for a form, containing all the options in the CBO - Brazilian Code of Occupations
Other than CEP, which does not have an official free base, in MTE download area there is a file txt, where the professions and the code of each one are listed (inside the page of the link above has the link: Estrutura CBO (TXT) - Arquivo ZIP (106kb)
- is the fourth archive, CBO2002-Ocupacao.txt
).
So what I want to do is take this file and generate the code automatically, including the professions and the respective CBO numbers in the file. js (as in the full example below). This is possible?
I’ve already created the autocomplete
, using the plugin Jquery-ui, but I got discouraged from writing all the professions and codes in my fingernail and here I am.
In addition, I need the code not to be too heavy and slow to load. What is the best way to do this? With database, everything in the file . js?
This is the autocomplete
(put all external links and is working on "run code snippet"):
$(function() {
var ocupacao = [
"Abacaxicultor (CBO 6125-10)",
"Abade (CBO 2631-05)",
"Abadessa (CBO 2631-05)",
"Abanador na agricultura (CBO 6220-20)",
"Abastecedor de caldeira (CBO 8621-20)",
"Abastecedor de linha de produção (CBO 7842-05)",
"Abastecedor de máquinas de linha de produção (CBO 7842-05)",
"Abastecedor de silos de carvão (CBO 6326-05)",
"Abatedor (CBO 8485-05)"
];
$("#profiss"). autocomplete({
source:ocupacao
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://code.jquery.com/ui/1.11.4/themes/start/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<form method="post" id="Cpost" name="Tpost">
<input type="text" id="profiss" placeholder="Informe a profissão"/>
</form>
So, long story short, the questions are as follows::
1 - Can you create the code automatically, from the . txt (or html) file? How to do this?
2 - How to make the loading of options not slow.
Updating: I still could not, I even made another file with the line breaks (it seems that what you can download on the site has no line breaks) to test, but I still could not make the script work. Succeeding, put the result here, but if anyone has another idea I’m accepting too. :)
Update: I converted the pdf into html file, and it got the following structure (the whole file has more 65k lines):
<DIV id="id_1">
<DIV id="id_1_1">
<TABLE cellpadding=0 cellspacing=0 class="t2">
<TR>
<TD class="tr5 td4"><P class="p9 ft2"><NOBR>7681-25</NOBR></P></TD>
<TD class="tr5 td5"><P class="p10 ft3">Acabador de chapéus de palha</P></TD>
</TR>
<TR>
<TD class="tr6 td4"><P class="p9 ft2"><NOBR>7663-05</NOBR></P></TD>
<TD class="tr6 td5"><P class="p10 ft4">Acabador de embalagens (flexíveis e cartotécnicas)</P></TD>
</TR>
</TABLE>
</DIV>
That helps?
/upate
Gustavo, why not use a json file that is much more "malleable"?
– KaduAmaral
I go there to find what is Json and come back. : D But I think it can be yes...
– gustavox
Quiet, it can be yes (who sees thinks I learned Json in two minutes, kkk, but I only saw that will give to understand after studying a little)...
– gustavox
A json is "basically" an object (or array, or object array, or object of arrays, etc...) in an external file, which you can load with ajax in javascript, or work with it in any other language, such as PHP, etc....
– KaduAmaral
But then just save txt with the extension . json?
– gustavox
For the record, we continue this conversation on javascript chat, and it’s come a long way, but it hasn’t been solved yet...
– gustavox